I have been working on a console script, and i ran into an issue that when i want to access a variable in a globally declared scene with a node using Project > Project Settings > Globals.
Within this global scene with a node, there is a function that is called everytime a player hits “Enter” that updates the RichTextLabel text ConsoleLog.text and passes that updated variable along to CLogText which is one of the ways i attempted to fix the problem, but to no avail.
I read somewhere about how there are basically 2 Autoloads for a global variable, the one you can modify in real time and the other one is stored and i assume its the one i keep refrencing instead of the updated autoload values.
Here is the code for the method that is supposed to update the displayed variables in the global class:
extends CONSOLECOMMAND
func RUN(args: Array[String]) -> String:
var myvar: String = ConsoleUi.CLogText
var myvar2 = ConsoleUi.CCHistoryIndex
ConsoleUi.ConsoleLog.text = ""
return ""
func _ready():
self.CC_NAME = "clear"
self.CC_DESC = "Clears the console. Nice and tidy."
self.CC_PREFIX = "c_"
Here is the function that calls the CONSOLECOMMAND script, aswell as the variables i am attempting to change. This is set within a global control node:
extends Control
var CCHistoryIndex: int = -1
var CCHistory: Array[String]
func Execute(Command: Array[String]):
print("[CONSOLE] Player Inputed: ",Command)
if CCDictionary.has(Command[0]):
var COutput_text: String = CCDictionary[Command[0]].RUN(Command)
print_log(COutput_text)
print("[DEVCONSOLE] COutput_text : ", COutput_text)
else:
print("[DEVCONSOLE][Execute] Returning function")
print_log("Invalid Command.\n")
I ran this multiple times through debug, step by step and have found out that the CONSOLECOMMAND’s myvar’s just keep grabbing null variables or empty strings even though i could observe the output in the global script and it updates in real time. How do i go about fixing this?
Offhand I can’t see anything obvious. Are you sure ConsoleUI is hooked up? Maybe try adding a print(delta) to _process() to see if it’s actually there.
It seems to be the same value everytime too. Its like the global variable im picking from is the one thats not getting updated. I tested out what if i change the default value of CCHistoryIndex, and after going up and down a bunch ending on the 2nd recorded index i ran the clear function and it said that myval2 was what i typed it out in the scipt but not what i updated it to if that makes sense
Its like there is a version of the global script thats the default version thats not running any functions and just servers as something to read only, and the other one is the one you can tamper with and currently interact with the console ui and functions within it