Feature Requeset: XML/INI Support
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Feature Requeset: XML/INI Support
It would be nice if there was native support for XML or INI for saves.
Good bye.
- Jasoco
- Inner party member
- Posts: 3725
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Feature Requeset: XML/INI Support
I find it's much better to use Lua for saves because all you need to do is write all the variables into it in the "variable = value" form, then load it or require it at game load and you don't have to do any parsing. Makes so much more sense to do it that way.
Some rudimentary code (Not actual code, just an idea of how the flow goes):
The saveSettings(function) could be called any time to instantly save all your settings. By printing it all so that it ends up looking like what the code would normally, you don't have to do any parsing or loading later. Remember to print everything as it should look as code. Like my example above, printing "variable1 = " as a string, then following it with the value of it (By actually printing the variable1) it will show up as the following, if say variable1 was "true"... variable1 = true So when you load the file, it will load variable1 into memory as true. See how flexible it is? And you won't need to use a third party XML parser or parse an INI. (Which most of the time I've seen consists of the same variable = value format)
Using love.filesystem.load(file)() will load and execute the lua file immediately which is what you want. Remember the extra () at the end. Otherwise it just loads but doesn't execute it.
Oh, and make sure to set the variables up before calling the saveSettings() function for the first time so it actually has values to write or else you'll get errors. It's all in that if/then/else part where it checks for existence of the file.
And remember, that's not actual code for the most part. I'm at Barnes & Noble so I can't code it up right, but if you're into Löve, I'm sure you can figure it out with the Documentation Wiki.
Some rudimentary code (Not actual code, just an idea of how the flow goes):
Code: Select all
if (file exists save_file.lua) then
love.filesystem.load("save_file.lua")()
else
variable1 = value1
variable2 = value2
...
--Save the file for next time
saveSettings()
end
function saveSettings()
open "save_file.lua" for writing
local tempVariable = ""
tempVariable = tempVariable .. "variable1 = " .. variable1 .. "\n"
tempVariable = tempVariable .. "variable2 = " .. variable2 .. "\n"
...
print into file tempVariable
end
Using love.filesystem.load(file)() will load and execute the lua file immediately which is what you want. Remember the extra () at the end. Otherwise it just loads but doesn't execute it.
Oh, and make sure to set the variables up before calling the saveSettings() function for the first time so it actually has values to write or else you'll get errors. It's all in that if/then/else part where it checks for existence of the file.
And remember, that's not actual code for the most part. I'm at Barnes & Noble so I can't code it up right, but if you're into Löve, I'm sure you can figure it out with the Documentation Wiki.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Feature Requeset: XML/INI Support
And, as jasoco points out, inis aren't that complicated, writing a parser would be trivial.
- Jasoco
- Inner party member
- Posts: 3725
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Feature Requeset: XML/INI Support
Every INI I've ever seen consisted of the same thing..
Which is basically the same thing a .lua file can do. Except you don't have to write a useless parser. So just print all the variables and values into a file in that same format and you can load it easily.
The difference is you can even write functions into it. As long as you print it into the file the same way it should be coded, you can do whatever. I don't think INI's or even XML could contain actual functions. And XML would be even more restrictive and take up more space with all its tags and elements. Just go the LUA route.
You could even do this:
If your game happened to store all variables as one array I guess. I don't know how your game works. Or will work.
Code: Select all
this = that
this = that
somethingelse = anotherthing
whatever = whenever
etc = andsoon
The difference is you can even write functions into it. As long as you print it into the file the same way it should be coded, you can do whatever. I don't think INI's or even XML could contain actual functions. And XML would be even more restrictive and take up more space with all its tags and elements. Just go the LUA route.
You could even do this:
Code: Select all
variables = {this, that, anotherthing, whenever, andsoon }
Re: Feature Requeset: XML/INI Support
Hm...this is an interesting way to do things. The problem is that if there is an error in the save for some reason, the entire game could crash. There should be some sort of exception handler for syntax errors etc.
Possible upside: if there is a function to compile Lua code, then you could make the saves harder to edit. Hm...
Thanks for the suggestion!
Possible upside: if there is a function to compile Lua code, then you could make the saves harder to edit. Hm...
Thanks for the suggestion!
Good bye.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Feature Requeset: XML/INI Support
To compile: string.dump()
To run with error checking: pcall()/xpcall()
All in standard lua.
To run with error checking: pcall()/xpcall()
All in standard lua.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Feature Requeset: XML/INI Support
introducing: pcall()Luiji wrote:Hm...this is an interesting way to do things. The problem is that if there is an error in the save for some reason, the entire game could crash. There should be some sort of exception handler for syntax errors etc.
Methinks that would be a bad idea.Luiji wrote:Possible upside: if there is a function to compile Lua code, then you could make the saves harder to edit. Hm...
Help us help you: attach a .love.
- Jasoco
- Inner party member
- Posts: 3725
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Feature Requeset: XML/INI Support
What, compiling Lua? What if we make a release game that we actually want to sell, or give away. Is there no way to keep the code from prying eyes? At least certain parts of it like the engine. I mean you don't see code for Cave Story or Portal. It's compiled into binaries.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Feature Requeset: XML/INI Support
LAME.
And, as I mentioned you can compile.
And, as I mentioned you can compile.
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 232 guests