First point: scripts != running code
Therefore both scripts must be part of the active scene tree. You do that by either preloading a script from the current one (using var myscriptobj = preload("res://myscript.gd")
) or by having the script autoload (from the editor menu, choose Project→Project Settings→Autoload and add myscript.gd to the list of autoloaded scripts). After that the loaded script can be referred to via the variable or by its global name (myscriptobj
in the first case, or Myscript
in the second).
Next point: separate scripts should not know anything about each other
So, to interact, the active script calls a function in the pre/auto-loaded script by name:
myscriptobj.somefunc(myvar)
Myscript.somefunc(myvar)
To make something happen you need to properly respond to an event. In this case, connect a signal (either using the Node panel on the right or manually in your scripts _ready()
function) that calls something. For example:
func _ready():
$Player.connect("signal_name", Myscript, "somefunc", [myvar]) # myscriptobj or Myscript
If the update needs to happen based on time or even every frame (as exampled here), just do it in the _process()
function:
func _ready():
set_process(true)
func _process(_delta):
# ignoring _delta means we just call somefunc() every frame
Myscript.somefunc(myvar)
Third point: you're probably doing it wrong.
You should create a scene that displays player stats. Attach a script that has functions that change the displayed information. Add the scene as a child node to your game screen scene and position it over your gameboard where you want to see it. Then use one of the above "To make something happen" methods to call one of the update functions:
func _ready():
$Player.connect("whatever", $PlayerStatus, "update_stats", [player_XP, player_GP, player_mana, ...])
or:
func _process(_delta):
$PlayerStatus.update_stats(player_XP, player_GP, player_mana, ...)
I hope it is obvious that "Player" and "PlayerStatus" and "player_mana" and the like are place-holders for whatever your variable names are.
Hope this helps.