0 votes

Hello, I am having trouble with a seemingly simple thing. I ran into the error in my main game and then made a testing script in an otherwise empty project to test it. I'm really at a loss for what I'm doing wrong.

Basically, I just want to check if my variable, which is a float number, is within a certain interval. Here is a picture of the code I wrote for the test script.

test script

The error log tells me: "Invalid operands 'bool' and 'float' in operator '<'.

But the numbers are float numbers on either side of the expression, and "test" is a float variable, is it not? Where is this boolean coming from?

I am running Godot 3.4.4-stable_win64 and using GDScript

Godot version Godot 3.4.4-stable_win64
in Engine by (15 points)
edited by

1 Answer

+1 vote
Best answer

That syntax isn't valid. You want this:

var test = 0
if test >= 0 && test < 100:

I assume the error comes from how the statement is resolved. Just guessing, but probably something like this:

if 0.0 <= test < 100.0

probably resolves to an intermediate state of:

if true < 100.0

Since the 0.0 <= test part is true.

Then, in the next round of resolution, you'd have a bool compared to a float, resulting in the mentioned error...

by (16,810 points)
selected by

Thank you, this makes sense. It was so ingrained in me from my math background to write intervals in the way I did so I never considered it would be unreadable in GDScript or other languages. I never would have considered this, thanks so much.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.