Getting "true" even when the string isn't the same

I’m trying to separate mobile and desktop inputs… but this keeps returning true even when I print out the os_name and clearly shows they’re different.


Screen Shot 2024-05-07 at 8.10.30 PM

And interestingly, if I reverse it, it works as expected…


:thinking:

The combination of == and or doesn’t work the way you intended it to. The or needs a bool on both of its sides. The left bool is os_name == "Android", and the right one is "iOS", which gives true when cast to a bool.

I think your if statement should be:
if os_name == "Android" or os_name == "iOS":

1 Like

You are indeed correct. Still adjusting to GDscript. This logic was valid in C#.
Thanks! :+1:t5:

1 Like

You’re welcome, glad I could help.

If you have a working version of the C# expression somewhere, I’d be interested in seeing that. It must have been at least a bit different (maybe array membership test), as the oeprator priorities should be pretty similar (but it should complain about the type mismatch, I suppose).

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms