All Questions


Casey McManus

Error: the assigned value doesn't have a set type?

I am trying to code the interrupted jump as part of the 'Make your first 2D game with Godot'. I am getting an error that says 'the assigned value doesnt have a set type: the variable type cannot be inferred" for the line where the is_jump_interrupted variable is declared.Can anyone help me?

    var is_jump_interrupted: = Input.is_action_just_released("jump") and velocity.y > 0.0

  • Nathan Lovato replied

    You can fix the error by adding the type `bool` between the : and the = sign.

    var is_jump_interrupted: bool = #...

    The ":=" operator tells the GDScript compiler to infer (figure out) the type of the expression on the right. Normally, it should see it's "bool", but GDScript's type checker has some limitations in Godot 3.2.

    In particular, depending on the version you use, some of those errors pop up.

    Whenever that's the case, you just need to specify the variable's intended type, like above.

    Hopefully, Godot 4 and the rewrite of the GDScript compiler should bring improvements in that area.

  • M
    Casey McManus replied

    Thank you so much, it worked!