Getting info from a dictionary

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.
Post Reply
mr bubbles
Grandmaster Poster
Posts: 120
Joined: Thu Jan 18, 2007 2:34 am

Getting info from a dictionary

Post 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?
User avatar
CWO
POL Expert
Posts: 1160
Joined: Sat Feb 04, 2006 5:49 pm

Post by CWO »

if namedic is a dictionary, wouldn't it be...?

Code: Select all

foreach name in (namedic.keys())
 Print(namedic[name]);
endforeach
mr bubbles
Grandmaster Poster
Posts: 120
Joined: Thu Jan 18, 2007 2:34 am

Post 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?
User avatar
CWO
POL Expert
Posts: 1160
Joined: Sat Feb 04, 2006 5:49 pm

Post 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.
Post Reply