Iterating through a StringMap

Monkey Forums/Monkey Programming/Iterating through a StringMap

Chroma(Posted 2013) [#1]
For Local b:Button = Eachin Self.buttons.Object()
		
Next

buttons is a StringMap. All I want to do is iterate through the values in the map. What am I doing wrong?


Chroma(Posted 2013) [#2]
Bah...it's buttons.Values(). I wish this was in the docs... Or probably because I was trying to use Object instead.


Goodlookinguy(Posted 2013) [#3]
Edit: Aw, I was ninja'd by you.

The Map class doesn't have an "Object()" method. Use the "Values()" method instead, e.g. "Self.buttons.Values()" instead.

Either that or Keys and grab each one. I don't usually use maps like you're trying to use them, so I'm not 100% sure of my answer.


therevills(Posted 2013) [#4]
For Local key:String = EachIn diddyGame.images.Keys()
	Local i:GameImage = diddyGame.images.Get(key)
Next


diddyGame.images is a StringMap which contains GameImages.


marksibly(Posted 2013) [#5]
Faster...

For Local img:=EachIn diddyGame.images.Values()
Next


Fastest...

For Local it:=EachIn diddyGame.images
   Local str:=it.Key
   Local img:=it.Value
Next



Chroma(Posted 2013) [#6]
Cool..thanks Mark.


Chroma(Posted 2013) [#7]
I know it's a moot point but would this be even faster?
For Local it:=Eachin diddyGame.images
	it.Value.Update()
Next