Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | JerryHayat |
I am working with a dictionary again, and I want to implement writing several keys.
I already have several keys in my dictionary and I want to add some more keys. I generate them, but not the essence. In my code, they replace the old ones.
Example:
match probability:
1:
dictionary_inv.itemDictionary = {
numberSlot:{'itemEq':['weapon'],
'itemIcon':preload("texture_path"),
'itemName':'30_carabine',
'a':true,
'b':1000,
't':quantity,
'x':'ammo',
'id':randi()}
}
*NumberSlot Generated in a specific range
I have several such keys and this one is approximate.
In the main dictionary I have 12+ ready-made keys
And this one replaces everyone
And a small additional question, in case the main one is solved
Can I delete keys in a specific range, for example 10 to 15? I know for sure that you can clear the entire dictionary, but this does not suit me
Thanks in advance :3
Sorry, I don’t quite understand the question.
Dictionaries map key->value
. You have a nested-dictionary structure with an outer-dictionary stored at dictionary_inv.itemDictionary
. This dictionary has 1 key-value pair, a key called numberSlot
which holds an inner-dictionary.
The numberSlot
inner-dictionary has 8 key-value pairs: itemEq->list
, itemIcon->resource
, itemName->string
, a->boolean
, b->integer
, t->integer
, x->string
, id->integer
.
To help with the first question. What is being replaced?
To help with the second question. Yes, you can delete a range of keys, but in order to delete keys range(10,15)
, the keys need to be integer
. Your dictionaries have string
keys.
Tim Martin | 2020-09-26 19:26
My main goal is Numberslot. Common dictionary example
var itemDictionary = { 0:{'itemEq':['none'], 'itemIcon':preload("res://data/assets/rpgsystemCardinal/Itemss/ammo/shot_shell.png"), 'itemName':'shot_shell', 'itemStack':true, 'itemStackMax':1000, 'itemStackValue':1, 'itemType':'ammo', 'itemId':randi()}, 1:{'itemEq':['none'], 'itemIcon':preload("res://data/assets/rpgsystemCardinal/Itemss/medic/medbac.png"), 'itemName':'medbak', 'itemStack':true, 'itemStackMax':64, 'itemStackValue':1, 'itemType':'consumable', 'itemId':randi()} }
:
It already stores 2 items under keys 0 and 1
I want to add another item through the script, under a different key, but it replaces the existing ones.
About 2 questions. That is, while I have a string
in my dictionaries, I will not be able to delete them correctly?
JerryHayat | 2020-09-27 06:29