• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Questions about Variables: true, false, int, string, etc.

H

Heat4Life

Guest
Hello there! I have a question that I am curious about... Is there like "Casting" system on GML? or am I just mistaken here?.... Well for example I putted an Instance Variable on my Create Event called jack = 3; then I created a Mouse Event and putted jack = true;... Will this even do It's job because jack is set to a number in-game but when I clicked the instance then I am setting jack to a boolean value...
 
M

Multimagyar

Guest
There is currently only Double floating points and Strings in Game maker when you store variables. Anything that is not 0 is true anything that is 0 counts as false. You don't need to cast it. But generally false will be 0 and true will be 1.
 
H

Heat4Life

Guest
There is currently only Double floating points and Strings in Game maker when you store variables. Anything that is not 0 is true anything that is 0 counts as false. You don't need to cast it. But generally false will be 0 and true will be 1.
Oh yeah... Thanks! :D
 
A

Aura

Guest
There's nothing like actual booleans in GML. In fact, true and false are built-in constants (Macros) that hold the values 1 and 0 respectively. So when you run this code:

Code:
jack = true;
...you're actually setting jack to 1.
 
There are a few other data types then just doubles and strings. There's also the special data type 'undefined', arrays are technically their own data type, pointers (which are currently only used for a small number of functions), and enums. A futher note for booleans, while the constant values of 'true' and 'false' are equal to '1' and '0' respectively, when performing comparisons (ie: "my_value == true"), values are considered 'true' if above '0.5' and 'false' if below '0.5', including negatives.
 

TheouAegis

Member
There was an issue once when GMS treated -1 as true, which is how -1 is handled in other languages; however, Russ said this was a bug, as GM's devs have intended to keep negatives as false (unless otherwise noted at a later time).

So if you want to go on to use other programming languages, just be aware that Multimagyar's post is correct for many programming languages, just not Game Maker.
 

jo-thijs

Member
There's nothing like actual booleans in GML.
That's what the manual wants you to believe, but it's not true!
I almost made a thread about this a couple of days ago, but decided not to post it, because I didn't really ask any serious questions.
I saved it in a word document as back up and left it there.

Anyway, there's a function is_bool in GameMaker that is not documented, but is fully functional.
If you try:
Code:
show_message(is_bool(0));
It will show 0.
If you try this:
Code:
var a = 0;
show_message(is_bool(a != 0));
It will show 1.

Even more so, if you add a real number to a "true" boolean, it will give a boolean value 0 or 1, despite whatever number you added to it.
Just try this:
Code:
var a = 0;
show_message(2 + (a != 0));
You'd expect this to show 2, but it shows 1 instead.

However, the rest of your post is correct, as GameMaker treats the keywords "true" and "false" as real numbers.
And to make matters even more confusing, boolean evaluations of which the result can easilly be decided on compile time,
will also be treated as real numbers, so this:
Code:
show_message(is_bool(0 != 0));
will show 0.
Probably because they're replaced by the keywords "true" and "false", which aren't "true" booleans.

This is a thing that caused me some issues and confusion in the near past.
 
H

Heat4Life

Guest
It would be great If the GM:S Devs make negative values as "false" actually...
 

jo-thijs

Member
What?
I think you left something out there, because that does equal 2.
I was trying to remember that by hard, but apparently, I had it remembered wrong.
It was actually this:
Code:
var a = 0;
var b = a != 0;
show_message(2 + b);
I'm not sure though why what I posted before does show 2, while this one shows 1.
 

TheouAegis

Member
@jo-thijs .......Wow. Have you or anyone reported that to the devs? Not many people take advantage of that, I bet, but still -- it's a game-breaking bug. If they wanted to have b register as a bool, that's one thing, but by forcing an int to be a bool just because it's added to a bool, that changes the mechanics quite a bit.
 

jo-thijs

Member
I know it can be quite game breaking, as it broke one of my games.
I haven't reported it yet and I don't know if anyone else has yet.
I have been lazy lately with reporting things, because GM:S 2 might come and change everything completely anyway.
 

jo-thijs

Member
Mantis is still being used?
Well, I still have my account, but I can't find how to report something on it.
I used to be able to easily report things there.
 

TheouAegis

Member
Maybe mantis is gone. I just used the yoyogames.com/bug page. Hopefully that one's working. Then they'll be like, "please upload an example" even though I said in the URL "just copy my code into a clean project and see for yourself".
 
I've had issues in the past with dealing with booleans as well, but they only really cropped up using YYC. And I did get some really unusual values that didn't make any sense either. Suffice to say, one has to be careful with math and boolean expressions!
 

GMWolf

aka fel666
GM:s went from just having doubles and strings (at least, from our perspective) to suddenly including a whole load of typing. i dont think all of the engine has been changed to reflect the changes though as its still quite buggy.
but as a general rule: treat true as 1 and false as 0.

The reason they used <0.5 as false is due to rounding errors with floating point values.
 
N

NPT

Guest
I was trying to remember that by hard, but apparently, I had it remembered wrong.
It was actually this:
Code:
var a = 0;
var b = a != 0;
show_message(2 + b);
I'm not sure though why what I posted before does show 2, while this one shows 1.
This appears to be fixed in EA v1.99.475
 
Top