I'm coming from more OO languages (Java, C++, C#), so it's a bit hard for me to wrap my head around how lua handles objects.
I have a user object declared as follows in a User.lua file:
local User = {align="neutral", justness=50, sceneData=nil};
I attempt to convert it to JSON to save in a text file like this in the User.lua file
function User:save ()
print ("Saving game state")
local data = json.encode(self);
local file = io.open (path, "w");
file:write ( data );
io.close( file );
file = nil;
end
The function call is:
User:save();
And the program just saves [] in the text file. How do I reference the object in such a way that it saves the table data? (Edit:) I would like to be able to save the table and make it so that I am able to create a new object with the data in the table after the user closes and reopens the app.
Additionally, sceneData is an object of class Scene, will that encode the table data for that Scene object, or will I need to fiddle with that as well?