• 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 Boolean vs Real

N

NeonBits

Guest
Boolean (true, false). Real (123). True = 1. False = 0; if "varA" was boolean at first in "create event", and then I write something like "varA += 0.1"; or if it was "real" and then I make it "boolean", will GM follow without being upset, as long the code follows the changes? Or boolean must always stay boolean and real a real value?
 
N

NeZvers

Guest
Yeah! I don't know technical background but everything possitive will be equal to true and 0 and bellow is equal to false.
 
N

NeonBits

Guest
Yes, but if I'm only turning my varA into a timer, there's no more check for boolean value, it must be ok, no? I mean, the var is boolean in create event. If in step I choose to make it a timer directly and not after checking if it's true or false, things must be ok, right?
 
D

dannyjenn

Guest
It used to be the case that 'true' and 'false' were constants (or maybe keywords?) which signified reals whose values were 1 and 0 respectively. So if you were to have added 0.1 to true, you'd end up with 1.1 (which GameMaker would then regard as true when checking conditionals). Likewise, if you'd added 0.1 to false you'd end up with 0.1, which GameMaker would regard as false (because everything less than .5 is regarded as false).

GameMaker Studio 2 changed things up, since there are now actual data types (whereas before everything was a real). But GameMaker does all the casting automatically, so if varA started off as true and you added 0.1, GameMaker should have no problem doing the addition... you'd still end up with 1.1 which would evaluate to true when checking conditionals. The only difference would be that typeof(varA) would return 'bool' before you perform the addition, and typeof(varA) would return 'number' afterwards... since the addition itself is what triggers the boolean-to-float casting. At least I think that's how it works.
 

Surgeon_

Symbian Curator
GameMaker does not have a boolean type. The only numerical type it has is real (with the other non-numerical types being string, array, undefined etc.). And the keywords "true" and "false" are basically macros that expand to 1.0 and 0.0, respectively, though GameMaker treats any value of 0.5 and above as true and others as false (if I recall correctly).
 
D

dannyjenn

Guest
GameMaker does not have a boolean type. The only numerical type it has is real (with the other non-numerical types being string, array, undefined etc.). And the keywords "true" and "false" are basically macros that expand to 1.0 and 0.0, respectively, though GameMaker treats any value of 0.5 and above as true and others as false (if I recall correctly).
GameMaker does have a boolean type, as well as other data types: https://docs2.yoyogames.com/source/_build/3_scripting/3_gml_overview/checking_data_types/index.html
Everything is implicit though. A variable can be a boolean, but there's no way to define a variable as a boolean. GameMaker does that all automatically. But if in the create event you do varA = true; and immediately afterwards you print is_bool(varA), it should print true, or if you print typeof(varA) it should print "bool" (I've never actually tested this though, as far as I can recall).

For anyone who wants to give it a try, do this:
Code:
var varA = true;
show_debug_message(typeof(varA));
varA += 0.1;
show_debug_message(typeof(varA));
I predict that it will print
Code:
boolean
number
(If it doesn't print that output, I guess I'm wrong about all this, so please disregard what I've just said in these last two posts.)
 
Last edited by a moderator:
Top