How do i change a timer's wait time while changing scene?

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

I want to change my timer’s time in another scene, my code is currently like this

func _on_btn_easy_pressed():
get_node("/root/world/spawner_enemy").time = (2.5)
get_tree().change_scene("res://stages/stage_game.tscn")
pass

while my code on the spawner_enemy, i have

   var time = 2.5 setget set_time
    
func set_time(new_value):
	time = new_value
	$Timer.wait_time = time
	pass

but all i get is node not found: /root/world/spawner_enemy
or Invalid set index ‘time’ (on base: ‘null instance’) with value of type ‘float’.

help?

In which scene is your spawner_enemy? If it is in stage_game, you should move your line of code after you changed to that scene. Before, the node is not here because it’s not added yet.

Zylann | 2019-03-29 13:46

The error “Invalid set index ‘time’ (on base: ‘null instance’) with value of type ‘float’.” appears when i do that

Lapsyy | 2019-03-29 14:01

The code you posted shows the opposite. In any case, it means the node is not currently in the scene when you call it (or not at the correct path).

Zylann | 2019-03-29 19:30

:bust_in_silhouette: Reply From: malkav182

I think it still not finding the spawner_enemy even if you move that line below your change_scene. If you have a node spawner_enemyon stage_game, just use

$spawner_enemy.time = (2.5).

Your error indicates that the script isn’t finding that node.

The problem i had was it was the timer was also in different scene which means the timer still havent existed but i now fixed my problem by using a global variable but thank you!

Lapsyy | 2019-03-31 08:58