Godot Version
4.2.2
Question
Hey, I want to upload a variable multiplier
when a scene is ready. I made a signal that upload multiplier value, but when other signal use this variable, the upload doesn’t have effect (returns to its original value):
#Script habitat
class_name habitat
extends Control
@onready var lvl: float = 1.2
@onready var manaAdded = 8 #coin 1
signal level(lvl)
signal addMana(manaAdded)
@onready var time = 3
# Called when the node enters the scene tree for the first time.
func _ready():
level.emit(lvl) #upload multiplier variable
%timer_habitat.start(time)
func _on_timer_habitat_timeout():
addMana.emit(manaAdded) #add a value
--------------------------------------------------------
#Script coin 1
class_name coin_1
extends Node
@onready var multiplier: float = 1.0
(irrelevant code)
func _on_container_habitat_level(lvl): #signal that upload multiplier
multiplier = lvl
print(multiplier) #print 1.2
func _on_container_habitat_add_mana(manaAdded): #signal that add a value
print(multiplier) #print 1
var lvl = roundi(manaAdded * multiplier)
add(array_num(str(lvl)))
Signal level(lvl)
is emitted first, so it’s supposed to change multiplier before signal addMana(manaAdded)
use it, but it doesn’t. I try to make multiplier a setter, but nothing change.
If anyone know why, please let me know. Good day