+2 votes

I'm trying to clean up some code that has a ton of if statements with a ton of:


I thought you could clean it up by putting it in a variable:

var pressUp = Input.is_action_pressed("ui_up") 

It does not seem to work. It lets me run the game, but the inputs stop working. I'm pretty sure I'm missing something simple.

in Engine by (541 points)

1 Answer

+3 votes
Best answer

Sure. Input.is_action_pressed returns bool so you can use it like this:

var left = Input.is_action_pressed("ui_left")
var rigt = Input.is_action_pressed("ui_right")

if left:
elif rigt:
by (368 points)
selected by

Thank you for taking that off my list, so I could fine what was really wrong. It ended up being a logic problem.

@JTjonny ~ If this answer has outlined the solution, make sure to mark it as "accepted" by checking the checkmark :).

@Bojidar Marinov - Sorry, new to this. I just did it.

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 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 webmaster@godotengine.org with your username.