–1 vote

I've been trying for a while now to make this script work, the code that i've wrote for it currently grabs a new instance of the "GridSizeUI.gd" script, but i want to make so that the Script grabs the actual "GridSizeUI.gd" script, because any updates that happen to the original script don't appear in the new instance

What could i do in the code to make that happen?

extends Label

var GridSizeUI_Script = load("res://Scripts/Grid_Size_UI.gd").new()

func _process(delta):
    text = str(GridSizeUI_Script.NT)
    print(text)
Godot version Godot 3.2.3
in Engine by (34 points)

2 Answers

+1 vote

I can't understand that. It sounds like You just want to print actual NT variable of some gridzise instance. Instead of creating new script just use reference to this one original gridsize instance, that keeps actual values of NT. It is somewhere in your scene, isn't it ?

by (7,742 points)

Do you know of any way through which i can do that?

The script i'm trying to access and this script i've shown the code to are in two different scenes

Ok, but how do You update script in another scene ? Is it some kind of tool scene, which You run and it saves variables to this scipt for use of whole project ? Or is it more like previous level scene and You want to keep data to next level ? Or is it a scene that You only tweak in editor and You want it to be kept for whole project ? Please tell more about what is this script for

+1 vote

You probably want to make Grid_Size_UI a Resource instead of a script. Doing so will make it so there is only ever one Grid_Size_UI object in memory.

Everything you would want to know about resources from Godot:
https://docs.godotengine.org/en/stable/getting_started/step_by_step/resources.html

An easy to follow tutorial about how to use resources:
https://kidscancode.org/godot_recipes/basics/custom_resources/

by (3,870 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.