GameMaker Function is_bool() not working properly on object variables?

F

Finn

Guest
I have an object with an object variable that is boolean (see screenshot).
When I check in the create event if the variable is boolean using "is_bool()" it will return "false".
-> Any ideas what could explain this behavior?

Note: The variable is not changed anywhere before to another type and not modified in any way.
Note: I tested whether instea dof using is_bool() I can use
" oVar_ability_newState == true || oVar_ability_newState == false "
This works see below in screenshot.
upload_2019-7-31_2-9-8.png




Another test:

Code:
show_message( "is_bool()-test: " + string(is_bool(true)) );
returns " 0 " a.k.a. "false".

upload_2019-7-31_2-22-29.png
 

Attachments

Last edited by a moderator:

TheouAegis

Member
I'd file a bug report. GMS has a history of bools being reals even though they are documented as bools in the manual and elsewhere. Even functions returning true/false don't technically create bools. However, it's reasonable to expect a varible definition to be what you set it to be, and in GML it would have been a bool if defined as a bool. Then again, GM would also lock certain variables such as x and y to reals even if you tried to force them into bools, so perhaps the same is going on here.
 
F

Finn

Guest
Wow. so the very function "is_bool()" does not actually return a boolean type?
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
Wow. so the very function "is_bool()" does not actually return a boolean type?
is_bool does check if the value is a "true" boolean, but many functions that you might expect to return booleans return 0 or 1.
 

TheouAegis

Member
You could force definitions as bools. It's more work and messier/slightly slower, but it should work as a crutch. lol
Code:
oVar_ability_newState = oVar_ability_newState==true;
Same with storing function results to a variable.
Code:
var temp = place_meeting(x,y,oBlock)==true;
Except I'm not sure what happens if you try to ! such bools. Do they stay bools? Do they get reverted to reals and then inverted? I dunno, never bothered to test it.
 

Joe Ellis

Member
Why do you need to ask if it's a bool? I've never come into a situation where I need to ask this, there are only 3 main types: string, array and number\real
 

FrostyCat

Redemption Seeker
Why do you need to ask if it's a bool? I've never come into a situation where I need to ask this, there are only 3 main types: string, array and number\real
I'll tell you one situation where asking whether it's a bool matters: Interoperability with things where the question matters.

As an example, interfacing with JSON-based APIs through json_encode() is a perfectly valid use case for GML. Yet for parameters that take Boolean values, it is usually not acceptable to put 0 or 1 in that position. It has to be an authentic Boolean. Failing to do this often results in validation errors on the other end, and in most cases it is not reasonable to demand that the API be bent just because the GML side can't get its type-handling act together.
 
Top