#Trying to change a value in a scene from clicking a button in a menu in another scene

1 messages · Page 1 of 1 (latest)

hybrid helm
#

the relevant code is as follows

#

Global.gd

extends Node

signal opponent_status(status)

var OpponentStatus = "Nullo"

func opponent_status_update(OpponentStatus):
emit_signal("opponent_status", OpponentStatus)
print(OpponentStatus)

#

#Menu.gd
extends Control

func inizia_partita():
get_tree().change_scene_to_file("res://Level/Level.tscn")

func _on_facile_pressed() -> void:
Global.opponent_status_update("Facile")
inizia_partita()

#

#Opponent.gd
extends CharacterBody2D

var speed := 250
var ball

func _ready():
ball = get_parent().find_child("Ball")
Global.connect("opponent_status", Callable(self, "_on_opponent_status"))

func _physics_process(delta: float) -> void:
move_and_collide(Vector2(0,get_opponent_direction()) * speed * delta)

func get_opponent_direction():
if abs(ball.position[1] - position[1]) > 25:
if ball.position[1] > position[1]:
return 1
else:
return -1
else: return 0

func _on_opponent_status(OpponentStatus):
print(OpponentStatus)

#

at the current moment the print() function in the global script does print the correct value, but the one in the opponent scene does not

#

also if there's a totally different system that's more elegant/efficient/anything Im down to learn it

hybrid helm
#

can I poke this or nah, not sure how this works