Possible Global Function problem?
Monkey Forums/Monkey Programming/Possible Global Function problem?
| ||
Function Main() New Game() End ''...imagine this function is an extern function that assigns a new ID Function ASSIGN_ID:int() Return MyExternIdGenerator() End Class Game Extends App '' etc... Global id:int = ASSIGN_ID() Method OnCreate() Print id ''in c++ this will call the function ASSIGN_ID() instead of returning the id value End End is that correct behavior to inline something that should be assigned? it does not do this to fields. i'd be ok for a work-around if anyone has one. perhaps have the global function call a classed static function? EDIT: even a classed static function doesn't work Function ASSIGN_ID:Int() Return Helper.GetId() End Class Helper Global id:Int=0 Function GetId:Int() id+=1 Return id End End |
| ||
This works here (glfw)...Import mojo Global x:=0 Function GetID:Int() Print "GetID()" x+=1 Return x End Class MyApp Extends App Global id:=GetID() Method OnCreate() Print "OnCreate()" Print id SetUpdateRate 10 End Method OnRender() Cls DrawText "id="+id,0,0 End End Function Main() Print "Main()" New MyApp End Funcs are called in expected order: GetID() Main() OnCreate() |
| ||
OK, thanks for the sanity check. I'll double-check my work. |