I'm developing a relatively simple top-down game, and I'm trying to make it so that the player can only perform a certain action after the player sprite has entered a specific area. For this I've set up an Area2D that successfully recognizes when the player enters the area (and exits the area), but I can't figure out to then after that have the action work only when the player is in that area. I've tried using if statements that recognize when the appropriate button (space) has been pushed in the signal function. I tried a boolean that changes to "true" when the player enters the area and then calling it later in the fixedprocess(delta) code, but for some reason the variable only reads as "false" even after the player has entered the area. (I've checked within the area enter function that the variable does in fact change to true, and it reads as true within that function.) I'm not quite sure what else to do. I feel like I'm just not understanding how functions work properly but I'm afraid I don't know enough to know what I don't know.
Here's how I've organized my nodes:
The "Player Area" node is a superfluous node I forgot to delete before I took the picture, and there isn't actually any useful script attached to "EntranceBu...", which is the Area2D node that is successfully detecting the player's entrance and exit.
The area enter code:
#this part works
func _on_EntranceButton_body_enter( body ):
print("Area was entered!")
var buttonarea = "true"
#but this part does not
print("Button was pressed!")
The code in the fixedprocess(delta) function:
var direction = Vector2()
var velocity = Vector2()
#player movement (which works, I'm leaving it just in case it's interfering somehow)
direction.y = -1
Playerdirec = "Up"
direction.y = 1
Playerdirec = "Down"
direction.x = 1
Playerdirec = "Right"
direction.x = -1
Playerdirec = "Left"
#velocity for player movement (which also works)
velocity = MAX_SPEED * direction.normalized() * delta
#the questionable code, it always prints, "Well, that didn't work."
if (buttonarea == "true"):
print("Button was pushed!")
elif buttonarea == "false":
print("Well, that didn't work.")
Thanks in advance.