0 votes

Hi! I'm following this tutorial on inventory/item stuff and so far I've had no problems with it.

I have, though, had a problem when trying to define the label text.
For whatever reason, the label won't add the text I've loaded to the dictionary to the scene when I load it up. It just comes back blank.

This is my code, all of it, just in case there is an error I've not noticed:

extends Control

var mapname
var loot
var loot_dic = {}

func ready():
name = "Sewers01"

func DetermineLootCount():
var ItemCountMin = ImportData.lootdata[mapname].ItemCountMin
var ItemCountMax = ImportData.lootdata[mapname].ItemCountMax
lootcount = randi() % ((int(ItemCountMax) - int(ItemCountMin)) + 1) + int(ItemCountMin)
print (loot
count, "Determine Loot Count Success")

func LootSelector():
for i in range(1, lootcount + 1):
var loot
selector = randi() % 100 + 1
var counter = 1
while lootselector >= 0:
if loot
selector <= ImportData.lootdata[mapname]["Item" + str(counter) + "Chance"]:
var loot = []
loot.append(ImportData.lootdata[mapname]["Item" + str(counter) + "Name"])
loot.append((int(randrange(float(ImportData.lootdata[mapname]["Item" + str(counter) + "Min"]), float(ImportData.lootdata[mapname]["Item" + str(counter) + "Max"])))))
dic[lootdic.size() + 1] = loot
selector = lootselector - ImportData.lootdata[mapname]["Item" + str(counter) + "Chance"]
counter = counter + 1
dic, "Loot Dic Success")

func PopulatePanel():
var counter = lootdic.size()
print (counter)
for i in get
if counter != 0:
node(str(i.getpath()) + "/Label").settext(loot_dic[counter][0])
counter = counter - 1

in Engine by (12 points)

1 Answer

0 votes

In the future, try not to post such a lengthy code snippet and use the code block formatting. Most people probably won't respond because they don't want to read it.

IDK if this is just an error made in posting but you have .settext(loot_dic[counter][0]) instead of .set_text(). I am surprised Godot didn't throw an error and let you know where that was.

by (594 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.