0

"I attempted to create a simple exit button. It initially worked, but then I accidentally erased my code and had to rewrite it. However, now it doesn't work at all, not even the _process(delta) function:

I attempted to have it print something

I also tried placing it in its own TEST.tscn scene, but that also didn't work.


# Variable that checks if the mouse is on the CollisionShape2D
var is_on = false

# Checks every tick. If the variable is_on is true, then if there's a left-click input, it will quit the game.
func _process(delta):
    print("MAKINGSURE")
    if is_on:
        if Input.is_action_just_pressed("ui_left"):
            get_tree().quit()

# Checks if the mouse is on CollisionShape2D. If true, is_on becomes true, and the Sprite changes to frame 1.
func _on_Area2D_mouse_entered():
    is_on = true
    $AnimatedSprite.frame = 1

# Checks if the mouse is on CollisionShape2D. If false, is_on becomes false, and the Sprite changes to frame 0.
func _on_Area2D_mouse_exited():
    is_on = false
    $AnimatedSprite.frame = 0````
Melwy
  • 1
  • 2
    "isn't working" is not a good problem description. Does it: a) do nothing b) output an error c) behave in an unexpected way? - I see you added a `print`, which I presume didn't give you output. But that does not tell me if there were no errors while running the code. If there was an error we should see about fixing it, otherwise the first thing I would check is if the correct script is attached. – Theraot Aug 15 '23 at 23:03
  • a), it doesn't output an error and I did a lot of re-attaching just to make everything more clear and easier, (so it should be attached correctly)(EXITbutton.gd to EXITbutton.tscn), (the sprite part works, what doesn't work is the exitting part), (I tried earlier to do or create something similar but with button and control node, now I am using Area2D and CollisionShape2D but still with Control node as a parent(Could that be the issue?(I've got Control-Mouse-Ignore))) – Melwy Aug 16 '23 at 00:29
  • you'd really need to attach your project or other files as I think this problem goes beyond your script. Your script however does not have `extends `. probably being `Area2D`, at the top,( perhaps that's missing?) – pm101 Aug 23 '23 at 12:04
  • I forgot to add that in the example, but it's there. – Melwy Aug 23 '23 at 20:12

0 Answers0