Code: Select all
myOOP = {}
Function myOOP:Create()
o = {}
SetMetaTable(o, self)
self.__index = self
o.varstosave = {}
o.anothervar = 2
Return(o)
EndFunction
Function myOOP:Save()
OpenFile(1, "ooptest.oop", #MODE_WRITE)
WriteTable(1, self)
CloseFile(1)
EndFunction
Function myOOP:Load()
OpenFile(1, "ooptest.oop", #MODE_READ)
self = ReadTable(1)
CloseFile(1)
SetMetaTable(self, GFXPack)
self.__index = GFXPack
DebugPrint(self.varstosave.test)
DebugPrint(self.anothervar)
Return(self)
EndFunction
testOOP = myOOP:Create()
testOOP.varstosave.test = 1
testOOP.anothervar = 3
testOOP:Save()
secondOOP = myOOP:Create
secondOOP:Load()
DebugPrint(secondOOP.anothervar)
DebugPrint(secondOOP.varstosave.test)
It seems like for some reason when I am using self = ReadTable, that self is only local and gets destroyed after exiting the function.
I can get around this by using return(self) but this seems odd to me.