how to make spawn only one node by click

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Bárbara Gabriela

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):"slime")
elif(state_now == 2):"slimezinho")
	var slime = slimezinho.instance()
elif(state_now == 3):"mini_slimezinhoinho")
elif(state_now > 3):
:bust_in_silhouette: Reply From: johnygames

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.