Bool Variable & Normal Variable
#1

Hello guys im just confuse that some people uses bool: for some variable or stock or even a new public function. can someone expalin me why? what's the difference between normal one? and with bool?

Normal Variable
pawn Код:
new Example[MAX_PLAYERS];
With Bool Variable
pawn Код:
new bool:Example[MAX_PLAYERS];
could someone explain what's the difference between those 2

Bool Varible Uses = true or false
Normal Variable = 1 or 0
Reply
#2

A bool variable can only be true or false
Reply
#3

Look in my signature for a tutorial on bools.
Reply
#4

@Adyzta i know that. but what's the difference about Normal on and bool one?

Quote:
Originally Posted by Rajat_Pawar
Посмотреть сообщение
Look in my signature for a tutorial on bools.
@Rajat_Pawar Looking at it now.

EDIT

just one question as i see on your tutorial. the godmode.

Mine

pawn Код:
new IsOnGodMode[MAX_PLAYERS];

CMD:godmode(playerid, params[])
{
    if(IsOnGodMode[playerid] == 1) //Checking if the 'state' of the player is GOD MODE.
        return SendClientMessage(playerid, -1,"You are already on god mode");
    if(IsOnGodMode[playerid] == 0) //Checking if the 'state' of the player is NOT GOD MODE.
        return SendClientMessage(playerid, -1,"You're god mode is already off!");
    return 1;
}
Yours
pawn Код:
new bool:isplayerongodmode = false;
CMD:god(playerid)
{
    if(isplayerongodmode == false) //Checking if the 'state' of the player is NOT GOD MODE.
{
 SetPlayerHealth(playerid, 999); //Setting the player's health to infinity.
 isplayerongodmode = true; //Setting the player's mode to 'ON GOD MODE'.
 }
 if(isplayerongodmode == true) //Checking if the 'state' of the player is GOD MODE.
{
 SendClientMessage(... "You are already on god mode!"); //Sending him the error message.
 }
return 1;
}
I can only see the difference is on bool uses true and normal one uses 1
Reply
#5

Well the normal variable you would have to add a ! to make a difference. For example,

pawn Код:
new playerGod[MAX_PLAYERS];
Then when you make a godon command.

pawn Код:
if(!playerGod)
will check if the player already has godmode on

pawn Код:
if(playerGod)
will check if the player has not got godmode on.

Whereas,

with the bool like:

pawn Код:
new bool:playerGod[MAX_PLAYERS];
You won't need !. It will just be like = 1 or = 0. or you can do = false or = true

say you were making a mute command.

pawn Код:
new bool:playerMuted[MAX_PLAYERS];
then in the mute cmd you will do
pawn Код:
playerMuted{ id } = true
then to check if the player is already muted

pawn Код:
if(playerMuted{ id } = true )
  return SendClientMessage(playerid, -1, "The player is already muted!");
Reply
#6

Well, it's basically your choice. I think there is an advantage of memory in bools -
since variables can take any value, and bools can, only true or false, I GUESS bools will be memory - savers.
I might/may be wrong ! But it's nothing much of a big deal, feel free to use it or not.
Reply
#7

Ok. Thanks for your advice.
Reply
#8

I read somewhere that in pawn, bools use the same memory as an interger.
So, in pawno there is no difference in bools and varibles beside the fact that bools can be only true or false.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)