If statement issues

Godot Version

Godot 4.2.1

Question

I am currently working on making a character move on a grid and I am having trouble getting an input to move the character. For instance, when I have the character move as it is selected with a button node, it works perfectly. This is part of the program that works:

func _on_nocturne_button_toggled(button_on):
	#false is first press
	if button_on == false:
		$NocturneSprite.play()
		$Sprite2D.show()
		nocturne_selected.emit()
		position.x += 32

However, if I put in an if statement to listen for a key press that I have set up under the name “Right” it does not trigger the movement. This is the code that does not work.

func _on_nocturne_button_toggled(button_on):
	#false is first press
	if button_on == false:
		$NocturneSprite.play()
		$Sprite2D.show()
		nocturne_selected.emit()
		if Input.is_action_just_pressed("Right"):
			position.x += 32

I am not a programmer by any means and I just picked up Godot a couple days ago so I may be using the wrong thing after the Input term or any number of things that are incorrect. Any help is greatly appreciated!

if i understand correctly, you are trying to move the character based on the 4 directional buttons pushed on the screen that you have placed? if that so, then no need Input.is_action_just_pressed, you just move the character according to the button it’s pressed, example the user pressed right button, then you take that as position.x+=32

is_action_just_pressed is only true after the button was released, and also only for 1 frame.

If you want to continually poll for whether the button is currently pressed, use is_action_pressed

ps: this is super minor and your code, your style, but fyi the convention with gdscript is to use lower case for strings and _ if you need a space, i.e. “Right” would be “right”. Welcome to Godot, btw, hope you love it.

The mighty documentation :grin: