Godot Version 4.1
Hello there, i’m posting here since i’ve been struggling looking for answers to my problem that i couldn’t find here, so here i go. I’m currently deving a mechanic that would be similar to a rythm game, for now i got notes that pops up and that go left.
They are being instanced in a bar that contains colliders for where is the note when hit. Tho by trying to dev this mechanic i knew i would need the use of signals and variables that are not in the main scene.
For example lets take my Canvas_layer which is where i store the HUD and so the main mechanic. we’ll call it scene1
And on the other side we got the little notes that pops up, they are a separated scene from scene 1, they are in the project but in another scene, they just get instanced to scene 1. the script to pop them up is introduced like so (i cutted parts of my script just to get the main thingy) :
(Script of scene1)
extends CanvasLayer
var BPM = 200
@export var BPMtotal = 60.0/BPM
var RythmMark = load("res://HitNote.tscn")
func _ready():
var BPMVarTimer = $"Until something respawns"
BPMVarTimer.wait_time = BPMtotal
func _on_until_something_respawns_timeout():
var rythmnote = RythmMark.instantiate()
rythmnote.position.x = $GNSP.position.x
rythmnote.position.y = $GNSP.position.y
add_child(rythmnote)
Lets take the child being added, rythmnote(scene2), i want to add a value to an inner variable from rythmnote and use his signals directly into the script of my main scene
for example in my rythmnote, i want to change the parameter "@export var location = 0"
of it directly from the script of Scene1 when it touches one of the area2d of my rythmBar
for example
func _when_area2D_touched():
instance.location = 1
-just an example
but i encountered the several problems which are not being possible to access a variable that is in a function and also using a function in a function, so honnestly i am lost… i’ve tried instance.connect but it doesn’t seem to change anything to my script…
also i would like to know how to access a signal from the instance of scene2 directly from scene1
Thanks to the one who’ll answer i’ve been searching for 3 days. Have a good day/night !