0 votes

I'm new to Godot and want to switch between two scenes when I press spacebar. I wrote this, but it is not working. Does anyone know why?

Code:

extends Node
export (PackedScene) var In
func switch():
    if Input.is_action_pressed("ui_accept"):
        var in = In.instance()
        add_child(in)
        remove_child($Out)
asked Mar 12 in Projects by Rykasi (12 points)
edited Mar 12 by Zylann

How are you calling switch?

Also note that in is a language keyword, you cannot use it for a variable name. Use another name, like next_scene.

I changed the names, but it still doesn't work. If I use a Timer to activate the switch, it works, but not with the input.

if Input.is_action_pressed("ui_accept"):

This is probably the line that prevents your code from running.
That line means "is the key bound to ui_accept currently pressed", is it what you intended?

Please log in or register to answer this question.

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.