Bool or int ?
#1

Hello,

I was wondering whhat is the difference between bool or int, as at final we can use equal to 1 for true and 0 for false
Reply
#2

You cant use bool for 3 options for example.
Reply
#3

If you're interested in use of memory, there's no difference in Pawn.
Both int and bool are stored on 32 bits.

If we're talking about values the int value 0 represents false and any other int value represents true.
Reply
#4

Bool usually works with if or else commands if you set bool="true" the given command will work for the player but if you set bool="false" the command may refuse to work for the player. Int refers to an integral value,setting int value to work as a bool maybe a very bad idea as it is not a good way of scripting nor it works in most of the cases and gives errors.
---------------
Hope it helps!
---------------
Reply
#5

Pawn only has one data type: the cell. The size of a cell is implementation specific. In SA-MP's case a cell is 32 bits. The tags (Float, Bool, etc.) are just there to define how the data in the cell should be represented. Therefore an int and a bool are exactly the same, safe for the way they are represented.
Reply
#6

Quote:
Originally Posted by Oxygenated
Посмотреть сообщение
Bool usually works with if or else commands if you set bool="true" the given command will work for the player but if you set bool="false" the command may refuse to work for the player. Int refers to an integral value,setting int value to work as a bool maybe a very bad idea as it is not a good way of scripting nor it works in most of the cases and gives errors.
---------------
Hope it helps!
---------------
Not true (regarding errors), a bool in PAWN is just a cell being 0 or 1 (to be precise any other value than 0). If you stick to this concept there is nothing wrong with using an int instead. There will be no errors with it either.

pawn Код:
new x = true;
Is technically the exact same thing as
pawn Код:
new bool:x = true;
or
pawn Код:
new bool:x = 1; // Will give a compiler warning, but works as expected (no error!)
or even
pawn Код:
new x = bool:1;
You can of course argue about good ways of scripting. It becomes clear that the variable is used to tell that something is either TRUE or FALSE, or ON/OFF. But that's pretty much it, if you know what you are doing and name Variables according to their use you can know this without using the bool tag.

PS: I'm not arguing for or against using the bool tag, but it's wrong to say there would be any errors or technical problems in using an integer as a boolean in PAWN. There can only be problems if you misinterpret the use of the variable.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)