I just started development for a game I have to design for school. When using gd in the script to make the character move right I get an error:

extends KinematicBody2D 

var motion = Vector2()

func _physics_process(delta):

    if input.is_action_pressed(ui.right):
        motion.x = 100


This is the line that is giving me problems

if input.is_action_pressed(ui.right):

and it keeps saying that ui is not declared in the current scope


1 Answer 1


I don't know why this should be a problem. Just do what Mertle told you to do.

"Who the heck is Mertle?" you might ask. "I don't know anyone by that name!"

That's exactly what the compiler is telling you:

"not declared in the current scope"

is the compiler's way of saying "I don't know who you're talking about. Who is this ui person who can tell me about .right? You haven't introduced us yet!"

You've used a new name that you haven't introduced before in this conversation (scope), so the compiler has no idea who you mean.

In fact, ui is not an object that the compiler can ask for a .right member.

"ui.right" is a string of text that you want it to pass to the is_action_pressed function as-is.

To pass a string, you must put double-quotation marks around it, so the compiler knows to treat it as a blob of plain text, not an expression or variable to parse and evaluate.

So, replace this with:

if Input.is_action_pressed("ui_right"):

...as shown in the Godot documentation on Input events.

As a general rule, when following a programming guide, every character is important. You can't leave any out. So check your examples carefully to make sure you typed out everything. The capitalization of Input is important too!


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .