Reflection + me being dumb
Monkey Forums/Monkey Programming/Reflection + me being dumb| 
 | ||
| I'm preparing to get my head around using reflection to easily save game status. I know I must be missing something very simple, but when I attempt to run the following I get Identifier 'GetGlobal' not found. This is taken straight from the docs without edits Import reflection
Global MyGlobal:=123
Function Main()
'Get GlobalInfo for MyGlobal 
    Local g:=GetGlobal( "MyGlobal" )
'Read and unbox value of MyGlobal
    Local n1:=UnboxInt( g.GetValue() )
'Print it...
    Print "n1="+n1
'Box and write value of MyGlobal
    g.SetValue( BoxInt( n1*2 ) )
'Read, unbox and dump...
    Local n2:=UnboxInt( g.GetValue() )
    Print "n2="+n2
EndWhat am I missing? Ta! -Chris | 
| 
 | ||
| So I know what I was missing. It's because I saved the source file as  reflection.monkey.... I've done this with something similar before! Oops. Here's a picture of a dog on a skateboard as a sorry for wasting your time   | 
| 
 | ||
| glad you reflected on your mistake | 
| 
 | ||
| Ok, I don't think this one is quite as dumb of a question... I'm getting the error Cannot call method m_SetValue of null when attempting to set a value that has been read from the save file... 
Class AS
    Global anInt:Int = 10
End
Function LoadStuff:Void()
    Local cInfo:=GetClass("AS")
    ' STUFF MISSED OUT HERE
    Select type
	Case "IntObject"
		Print "Settings "+name+" to "+Int(item[2])
		cInfo.GetGlobal(name,false).SetValue(BoxInt(Int(item[2])))
    ' MORE STUFF MISSED OUT
End
At the point of the error (the line containing SetValue), the variables are as follows... type = "IntObject" name = "anInt" item[2] = "10" Any clues? Ta :) -Chris | 
| 
 | ||
| Aha, got this one too :) Where I have name, it needs to be "src.appstate.AS."+name |