I'm trying to make a loading and saving system that is generic. Anyone know how to go about making blitz max create a type instance from a string that looks something like "new agent"? This is text that would be in a text file that I would load to recreate my type data
here's what my save data file looks like...
the "new" is in there just to denote that a new type is to be created, the "agent" is the name of the type in my code. Then below is all the fields and that data.
here is my non-working code for both parts of the process as I have now.
here's what my save data file looks like...
new agent state 500 x 304.000000 y 100.000000 z 50.0000000
the "new" is in there just to denote that a new type is to be created, the "agent" is the name of the type in my code. Then below is all the fields and that data.
here is my non-working code for both parts of the process as I have now.
Function saveType(instance:Object,file:TStream) Local id:TTypeId=TTypeId.ForObject(instance) Local fList:TList = id.EnumFields() WriteLine file,"new " + id.name() For Local myField:TField = EachIn fList WriteLine file,myField.name() + " " + myField.getString(instance) Next End Function Function loadTypes(filename:String) Local file:TStream = ReadFile(filename) Local myLine:String Local myAgent:agent While Not file.Eof() myLine = ReadLine(file) Local myCom:String[] = myLine.split(" ") Select myCom[0] Case "new" Local id:TTypeId=TTypeId.ForName(myCom[1]) Print id.name() myAgent:agent = id.newObject() Default setAttr(myAgent,myCom[0],myCom[1]) End Select Wend CloseFile file End Function Function setAttr(instance:Object,fieldName:String,value:String) Local id:TTypeId=TTypeId.ForObject(instance) Local myField:TField=id.FindField(fieldName) myField.setInt(instance,Int(value)) End Function