How do I delete a dictionary key once I've used it?

Get help using Construct 2

Post » Wed Dec 09, 2015 9:29 pm

Hello again!

Sorry for the second post of today, but I'm completely stumped.

I have a dictionary that is being fed from an external file via AJAX, that works perfectly now. This file contains 15 names that are stored in 15 keys. When I run my layout it creates 12 instances of one sprite and sets an instance variable called "name" for each and that works fine. However, what I would like to do is once the sprite has been named, I would like to remove that name from the dictionary so there won't be any duplicates.

Image
Here is the block of events that spawns all the objects and assigns the instance variable.

Once again, I apologize for the second post and thank you in advance,
Jack.
B
4
Posts: 3
Reputation: 206

Post » Fri Dec 11, 2015 12:50 pm

@foxpawgames
Image

you can simple delete key in your example if you use let's say variable "varRND"

set"varRnd"= int(random(Dictionary.KeyCount)
name=DictionaryGet(varRnd)
delete key varRnd

but now you have another problem...

here is the difference between Dictionary(when the delete key) and Array(when you delete cell)
Image

ArrayRandomNames.capx

DictionaryRandomName.capx
B
66
S
24
G
7
Posts: 1,514
Reputation: 11,039


Return to How do I....?

Who is online

Users browsing this forum: divsyntax, pmerineau and 11 guests