How to access variable in script outside of scene?

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

I have a main menu scene which uses get_tree().change_scene("res://Scenes/Game.tscn
to start the game. The “Game” scene’s root node is simply called “Game” too. It has a script attached to it containing a variable. How can I go about changing the variable’s value from the main menu script after calling get_tree().change_scene()?

:bust_in_silhouette: Reply From: ramazan

var game = load(“res:”).New()
game.player_speed = 50

(player_speed . Game scene script var)

I tried the following: var game = load("res://Scenes/").New() , but it gives me this error: Invalid call. Nonexistent function 'New' in base 'GDScript'

What went wrong?

pion | 2022-01-28 12:52

var game = load(“res://Scenes/”).new()
“New” = “new”

alternative method
Groups — Godot Engine (latest) documentation in English

ramazan | 2022-01-28 13:50