Is there a way to compare two Boolean variables?

It’s not that big of a deal, but I wonder… Regular int/string variables can be compare
But Boolean seems to miss this function?
v1
v2

Unfortunately, they don’t treat booleans the same as numbers and strings. I wish they did.

Other than using a different format like one and zero, the best I can think of is to use an OR with 2 Ands. It’s not as straightforward but let’s you keep the booleans.

You could create your own condition, so it’s more readable.

What if you compared them as json text?

This works correctly.
image

:sweat_smile: Ugh? I am already trying to compare a Boolean value from a json file, so my head is spinning. What is that? I really admire your first solution, it’s both beautiful and ugly in the same time lol.

what’s that? string? :thinking:

Yes
image

Oddly it works with compare string and compare numbers. I wonder what values it’s using. It seems to be using 0 and 1 for number and “true” or “false” for string.

I’d be careful. Since that doesn’t seem to be documented. The behavior could change in the future.

It would be nice if someone from GD would share their opinion.

It’s hideous but it’s elegant in the way that it maintains the format. It’s a bit like taking 3 left turns instead of one right.

Most likely, this is due to the fact that GDevelop is written in JavaScript, and it’s not typed. Although gdevelop also has code in TypeScript and C++, the variables are probably programmed in JS.

number = randomInRange(1, Infinity)
true == number
number = randomInRange(-Infinity, 0)
false == number
str = "true"
true == str
str = "false"
false == str
str = "8"
8 == str == true

I just looked at the source.

https://docs.gdevelop.io/GDJS%20Runtime%20Documentation/classes/gdjs.Variable.html#getAsBoolean

It does return a string or a number.

(By the stars @Keith_1357 wtf?)

Does not matter which you choose

To check if they DON’T match use INVERTED any of compare conditions
Or just set sign of the test to not equal

To check if both are the same you just compare both of them using
Any of compare conditions
(i lack this event in my screenshot below cause comparing if they are not equal already proves it would work)

To compare if both are true or if both are false
You again need one of compare conditions but additionally check just if one of them is true or if one of them is false