Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | lgmeister |
I’m trying to pull a variable from my dictionary and then print/put it in a textbox as what the variable equals. Instead, it’s printing the string “globals.shipName”. Ideally I would like to have both a string and variable (i.e. “Welcome to the %s” %globals.shipName) but I can’t for the life of me figure out how to put a variable in a string in a dictionary. Any help would be nice.
In a separate script that is autoloaded loaded as “globals”
var shipName = "U.S.S Enterprise"
main script
func dialogLoad(): ### Pulls the data from testdialog.json
var file = File.new()
if file.file_exists("res://RSdialog/testdialog.json"):
file.open("res://RSdialog/testdialog.json", File.READ)
var tmp_data = file.get_as_text()
file.close()
globals.dict = {}
globals.dict = parse_json(tmp_data)
print(globals.dict) ### The results are {1:{final:0, name:Mr. Spock, text:globals.shipName}, 2:{final:0, name:Captain Rambo, text:Let's go for a spin!!}}
func dialogStart(): ### Starts the conversation
textboxHeader = get_node("/root/main/dialogbox/dialog_med/dialogLabelHeader")
textboxHeader.set_text(str(globals.dict[str(globals.convoID)]["name"]))
textboxMain = get_node("/root/main/dialogbox/dialog_med/dialogMessageBox")
var messageConvert = globals.dict[str(globals.convoID)]["text"]
messageConvert = str2var(messageConvert)
print (messageConvert)
textboxMain.message = messageConvert