0 votes

I am trying to make a node appear on the side of the player and the player changes animation when pressing enter, but while it is in the second state it continues to spawn until pressing enter again. I just want it to appear once.

Here is the code:

states variables

const slimezinho = preload("res://scenes/slimes/slimezinho.tscn")
onready var state = $player_sprite
var state_now = 1

change state

    state_now += 1

#change sprite
if(state_now == 1):
elif(state_now == 2):
    var slime = slimezinho.instance()
elif(state_now == 3):
elif(state_now > 3):
in Engine by (20 points)

1 Answer

+1 vote
Best answer

I guess the problem arises because you have not indented the second part of your code.
See, you have probably put this in the _process(delta) function thus generating a new slime instance every tick of the game, regardless of whether you press enter or not. The first time you press enter, the game reaches state = 2 and, since you repeat the same process every tick, a new slime is created. Indent the second part properly.

by (1,848 points)
selected by
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.