How would I define an item with multiple values?

Ok so im trying to add a game to my discord bot and im adding certain items and they would have stats and I would like to do something to be able to do something like:

Hp = dictionary.get[armor, “hp”] 
Defense = dictionary.get[armor, “defense”]

And i know this probably looks horrible because its wrong but what I am trying to say is that i want to be able to grab the defense or hp from an item

Anyone know how i would write the dictionary so it would work(if it would be a dictioanary) and how i would get the hp or defense from that item

Since you posted this in Python, this should work:

armor = {"hp" : 9, "defense": 197}
#To retrieve:
HP = armor["hp"]
Defense = armor["defense"]
#To set:
armor["hp"] = 187
armor["defense"] = 917

Hope this helps!

1 Like

Would i be able to create a list with different items instead of making a dictionary for each item? Like

Armors = {
Armor 1: “hp” : 3, “defense” : 2,
Armor 2: “hp” : 4, “defense”: 5
}

Yes, like so:

armors = {
    "Armor 1": {"hp": 91, "defense": 19},
    "Armor 2": {"hp": 19, "defense": 91},
}

How would i grab the hp from each individual armors?

OP said without creating a dictionary for each item lol

No he’s correct, i wanted something like that

You could retrieve that like this:

HP = armors["Armor 1"]["hp"]
#Just change "Armor 1" to the armor you want
2 Likes

He still made each armor a dictionary, though

Yeah i was sort of unclear, I wanted to have 1 dictionary named armors and then have all the armors in it

1 Like

I assume OP meant like different variables:

A = {...}
B = {...}
#vs
C = {{...}, {...}}

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.