Page 1 of 1

Getting info from a dictionary

Posted: Wed Mar 21, 2007 12:26 am
by mr bubbles
Basically i have extracted info from a cfg file with the GetConfigStringDictionary() function.

I want to use the name and its corresponding value in a gump so need to loop through the dictionary and extract both (the names are random).

I've tried

Code: Select all

foreach name in (namedic.keys())
 Print(namedic.name);
endforeach
It doesn't like a variable being used i guess, anyone know of a way around this?

Edit: I'm doing 2 foreach loops to get around it, the second just loops (namedic) for the values of name. Dunno if its the only way to go about it, or is it the only way"

Edit2: foreach prop in racealigns (racealigns is a dictionary)
the _prop_iter returns the name of the prop instead of an iteration number. Is this right, or a bug with using it on a dictionary?

Posted: Wed Mar 21, 2007 10:55 am
by CWO
if namedic is a dictionary, wouldn't it be...?

Code: Select all

foreach name in (namedic.keys())
 Print(namedic[name]);
endforeach

Posted: Wed Mar 21, 2007 12:15 pm
by mr bubbles
Hmm, i've never really used dictionaries before (not any need) so though id trieat it like a structure. The namedic.name works though.

Can you explain a situation where a dict would be used over a struct?

Posted: Wed Mar 28, 2007 8:55 pm
by CWO
I use it when I either have references, pieces of references, or something else that would be variable for the name... like for example:


participants[CStr(who.serial)]

CStr() possible Ints otherwise you might get POL complaining that your dictionary is being used as an array.