I declare and use a variable in my code, but I get the warning code, that variable was never used, while being declared.
func _viewd():
if uself != null:
var feld = uself.find_child("TextureRect")
var feld2 = feld.find_child("RichTextLabel")
var feld3 = feld2.text
data = Global.load_json_data()
feld3 = data[str(num_them)][str(num_but)]["Text"]
cont = get_node("/root/Spiel/Tafel_tof").find_child("ScrollContainer").find_child("HBoxContainer")
count = 0
In the first code, I get this warning for all feld-feld3 variables and the text propertie doesn’t change. My second code isn’t working as well and I dont get it.
func _viewd():
if uself != null:
var feld = uself.find_child("TextureRect").find_child("RichTextLabel").text
data = Global.load_json_data()
feld = data[str(num_them)][str(num_but)]["Text"]
cont = get_node("/root/Spiel/Tafel_tof").find_child("ScrollContainer").find_child("HBoxContainer")
count = 0
Please can you explain your codes on what they are doing. Also the warning shown because you never used the field variables, just you set the values and never used them.
The function is called, when the visibility of an uself changes uself is a textureRect with a RichTextLabel. With “Global.load_json_data()” you load a json load function within an autoload. I only have one Json File to load, so i dont give a parameter with it.
uself, num_them and num_but are variables gives by a button, who changes the visibility.
So feld, which is the text propertie of the richtextlabel should become the string from json file at the point num_them, num_but, “Text”, but doesnt.
find_child() is expensive method and should be avoided
replace it and others to code like uself.get_node("TextureRect")
because in this script var feld-feld3 only receiving data, no variable that actually rely on them.
it is not necessary to store variable id to just for one action
do
data = Global.load_json_data()
uself.get_node("TextureRect/RichTextLabel").text=data[str(num_them)][str(num_but)]["Text"]
setting variable to property value in most cases returns only copy of that data, not property path.
it will work if you set
var feld = uself.get_node("TextureRect/RichTextLabel")
feld.text=data[str(num_them)]