Can you put an Input into var, to clean up code?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By JTJonny
:warning: Old Version Published before Godot 3 was released.

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

Input.is_action_pressed("inputName")

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.

:bust_in_silhouette: Reply From: Daniel Lewan

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:
	something
elif rigt:
	something
else:
	something

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

JTJonny | 2016-03-18 19:41

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

Bojidar Marinov | 2016-03-19 09:53

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

JTJonny | 2016-03-19 17:07