|
|
|
|
Reply From: |
p7f |
If you want to look something up in a dictionary, you should use that as key, instead of a number like 202 or 101. If you know sword is always going to be 202, you could ask
if 202 in DataImport.inven_data:
print(DataImport.inven_data[202]) #replace this by your actual code
That will print [Sword, 1]
If you really need to have the key 202, but need to look if some of the values is Sword, it dependes what is sword… if you have on the sword script something like class_name Sword
maybe you could do a for loop like this:
for item in DataImport.inven_data:
if DataImport.inven_data[item][0] == "Sword":
print(dict[item]) #replace this by your actual code
break
That would also only print [Sword, 1]
Is something like that what you are looking for?
201 -210 are keys that get populated randomly by the order of how the player picks up random loot.
So 202 will contain different things all the time. Should have mentioned this now that I think about it.
I think I will try setting up if statements checking if any item from 201 - 210 has combo “key number, Sword”, but that will be a lot of text.
AltoWaltz | 2020-09-15 13:09
And the loop i wrote in the answer doesnt work for you?
I get Invalid operands ‘String’ and ‘Array’ in operator ‘==’.
I tried with:
for i in DataImport.inven_data.values():
if DataImport.inven_data[i][0] == [Sword]:
print(i)
which returns first item in the dictionary which is not what I am looking for. The code below returns the values of the dictionary, I just cant figure it out how to approach single line returning boolean if the item value is there so I can do some further code.
for i in DataImport.inven_data.values():
print(i)
AltoWaltz | 2020-09-15 14:41
Sorry, that was why i asked if you had a class_name Sword or something
What is sword? an array?
Sword and other loot dictionary & inventory items are defined within json and most don’t have their own class, but some do. Sorry, this is the best as I can explain myself as this is my first godot project.
AltoWaltz | 2020-09-15 14:58