Save your game with reflection

Monkey Forums/Monkey Code/Save your game with reflection

slenkar(Posted 2012) [#1]
here is the module:
it takes care of cyclical references (objects that reference themselves)


here is the config module


you'll have to do some things to get it to work
1.make sure you have your reflection filter set correctly (or dont use one at all)
2.make all your classes that you wish to save extend saveable
Class saveable
Field unid:Int
End Class


you can only save one object, so you put all your game stuff in the fields of that one object

here is how to save 'my_world'
unique_int=0
If my_world.unid<>0
reset_ids(my_world)
Endif
serial_objects=New IntMap<Object>
local save_node:=object_to_node(my_world,Null)
SaveState (save_node.ToString())


and here is how to load:



Sets and Stacks are not implemented yet


Yahfree(Posted 2012) [#2]
Hey I'm trying this out.. My project uses angel font, and when I import these files into the main project I run this error in the angelfont source:

	Function Use:AngelFont(name:String)
		For Local af := Eachin _list
			If af.name = name
				current = af
				Return af
			End
		Next
		Return Null
	End
	

It says that af does not have the field name. af is a stringmap of AngelFonts. Any ideas? The error goes away when these files are not imported

Thanks!


slenkar(Posted 2012) [#3]
if af is a StringMap it doesnt have a name


Beaker(Posted 2012) [#4]
af is an AngelFont object.


slenkar(Posted 2012) [#5]
hmm ah dunno. the only thing I can suggest, is that you do:
For Local af:AngelFont= Eachin _list


instead of :
For Local af := Eachin _list


its a crappy suggestion and it probably wont change anything but its the only thing I can think of.


make sure that the object associated with _list has a field called name



Thinking a bit more it could be a bug with monkey as my GUI system messed up when I started using reflection, I had to just work around it.


Yahfree(Posted 2012) [#6]
I made the change you suggested and now I get the following compile error:

Compile Error

Cannot convert from Node<String,AngelFont> to AngelFont

The error goes away if I don't include this savegame code. Could be a bug with reflection?


slenkar(Posted 2012) [#7]
could you try making a little demo? thats the only way things get fixed.


Yahfree(Posted 2012) [#8]
I made a post in the bugs forum, just try importing reflection on the AngelFont demo packed with Monkey.