M
Maroderkon

Question about float variables

Hello!

I was just wondering about this line:

var player_has_won: float = timer.time_left > 0.0

Wouldn't this return true or false rather than a float number?


Thanks for the help!

3 loves
  • Xananax replied

    Uh, yes, completely correct! Thanks for catching that, we will fix this in the next update

    1 love
  • x
    xibasdev replied

    In connection to this issue, I've tried the following line of code:

    var player_has_won := timer.time_left > 0.0

    Imagining that it would infer the bool type for the player_has_won variable.

    But instead, I got this error:

     built-in:43 - Parse Error: The assigned value doesn't have a set type; the variable type can't be inferred.

    Does it mean Godot doesn't return a bool for comparison operators e.g. the > above?

  • Nathan Lovato replied

    Godot does return a boolean for these expressions but this may be a type bug in the GDScript parser in the version of Godot you are using. It should infer the type properly.

    If you don't have the latest stable version of Godot, then I invite you to download Godot 3.5 stable.

    If it's happening with Godot 3.5, then you can add bool after the :.

  • w
    warrioricon replied

    Yep, I just posted a question about this. I don't understand why the code even works when var player_has_won is a type float. A true or false value is being stored in it, isn't it?