How do I run my function named Close_Spike

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Sheggif

Hello I have been working on this game and I made this lazer that goes one and one with a spike which when the lazer gets touched for too long the spikes will activate(note that my player doesn’t have any hp so there is no tanking dmg) but when my lazer activates the spike wont close so you will come to an end and will have to go to menu and re play I have also thought of the possiblity of making it when you die just reset that scene but after remembering the finale level reseting the scene will reset your progress in the level so I am trying to avoid that at all costs. I have already made a closing function and it works when I activate it inside of my ready function but if I try to call it when the player dies it doesn’t work(though it wouldn’t be good as it will only close that certain spike). Just to clarify my problem is to reset my spike and I also will need a way to reset the Lazer
Here is my code if you need:
extends Area2D

const Open_Spike_Sprite = preload(“res://Assests/Tile Set/Open Spike.png”)
const Spike_Holder_Sprite = preload(“res://Assests/Tile Set/Spike Holder.png.png”)

func _ready():

func Open_spike():
$Sprite.texture = Open_Spike_Sprite
$CollisionPolygon2D.disabled = false

func Close_spike():
$Sprite.texture = Spike_Holder_Sprite
$CollisionPolygon2D.disabled = true

func _on_Spike_body_entered(body):
if “Player” in

func _on_Lazer_Open_spike():

func _on_Lazer2_Open_spike():

func _on_Lazer3_Open_spike():

func _on_Lazer4_Open_spike():

func _on_Lazer8_Open_spike():

extends Area2D

const Green_Lazer = preload(“res://Assests/Tile Set/Green Lazer.png.png”)
const Yellow_Lazer = preload(“res://Assests/Tile Set/Yellow Lazer.png.png”)
const Red_Lazer = preload(“res://Assests/Tile Set/Red Lazer.png.png”)

var Triped = false
var Has_been_Triped = false
var Lazer_detected = false
var Reset = false

signal Open_spike

func _physics_process(delta):

func Lazer_Checking():
if Triped and !Has_been_Triped:
$Sprite.texture = Yellow_Lazer
Triped = false
Has_been_Triped = true
if Triped and Has_been_Triped:
$Sprite.texture = Red_Lazer
Lazer_detected = true
Reset = true
$Sprite.texture = Green_Lazer

func _on_Lazer_body_entered(body):
if “Player” in

func _on_Timer_timeout():
if !Reset:
Triped = true
if Reset:
Reset = false
Has_been_Triped = false
Triped = false

func _on_Lazer_body_exited(body):
if !Lazer_detected:
$Sprite.texture = Green_Lazer

:bust_in_silhouette: Reply From: Lopy

If all your spikes share the same parent node, in that mother of all spikes, you could do :
for spike in get_children():
. spike.close_spike()

Otherwise, if only the player can open them, you could :

  • Put a reset signal in the player.
  • When a spike opens, it has access to the coliding player. You use this to connect its close_spike() to the players reset signal (CONNECT_ONCE).
  • When you emit the reset signal, all the spikes that where open close themselves.