Monkey Maps

Monkey Forums/Monkey Programming/Monkey Maps

Raz(Posted 2011) [#1]
Function ActivateMenu:Void(menu:String)
	If MenuList.Get(menu) <> Null
		' What I want to do
		MenuList.Get(menu).Active = True

		' What I think I need to do
		Local m:Menu = MenuList.Get(menu)
		m.Active = True
		MenuList.Set(menu,m)
	End
End

I have a list of Menu items stored in a StringMap (MenuList).

Am I able to manipulate these items without getting one, manipulating it and then setting it again?

Thanks
-Chris


Warpy(Posted 2011) [#2]
Class Menu
	Field Active:Bool
End

Global MenuList:StringMap<Menu>

Function ActivateMenu:Void(menu:String)
	If MenuList.Get(menu)
		Local m:=MenuList.Get(menu)
		m.Active = True
	End
End

Function Main()
	MenuList = New StringMap<Menu>
	
	'insert menu into map
	MenuList.Insert "hi",(New Menu)
	'activate menu
	ActivateMenu("hi")
	
	'check
	If MenuList.Get("hi").Active
		Print "active"
	Else
		Print "not active"
	Endif
End


You should be able to do it in one line, but it seems monkey's typechecker is failing. You certainly don't need to insert the object into the map again - the map only stores a pointer to the object.

This should probably get moved over to the bug forum.