HTML5 saving .ini files?

camerakid

Member
Hey Everyone,

So I have been testing for some time HTML5 and my games seem to be working nicely. But I have problems with the saving system... The standard ini file creating is not working and I have been reading the documentation about file handling but I am not sure if I am doing anything wrong. It says:

"HTML5 / Windows 8 (JS) - Everything is done through the local storage."

So when saving an ini file or reading from it, how would that look like? I tried both of the following methods but none has been saving the game (or I am not sure how to load them)

Code:
//Standard method
ini_open("Objects.ini");

//HTML5  method?
ini_open(working_directory + "Objects.ini");
 

camerakid

Member
The fact that you added was absolutely clear thank you for that one step closer to the solution. I was unsure with the method as I tried many and none worked. Yet.

So I have copied the save files from the appdata directory to the project's "included files" session and created an HTML5 build. I can see the ini files in the HTML5 directory.

For some reason after I uploading it to my server it is still not working as I would like to use it. When I click save and refreshing the page it never loads the saved game.

I have also tried to change the ini_open etc. containing the full web address
Code:
ini_open("http://***.com/html5game/Save.ini");
but it is not saving or loading any of the files for some reason.

I think I am missing something here.
 
Some ideas:

The line
ini_open(working_directory + "Objects.ini");​
should be correct. Afaik working_directory ends with a backslash. Just in case it doesn't: try
ini_open(working_directory + "\Objects.ini");​
On HTML5 target GM:S should convert any backslashes to slashes anyways so you don't have to worry about that however I don't know when that safety was implemented. So you might want to try:
ini_open(working_directory + "/Objects.ini");​

By now you should have your ini file in the included file ressource tree. If you made a group in the included files section and put a file in that group the file will be at:
working_directory + "groupname\" + "Objects.ini"​
or maybe with a blackslash but i think not:
working_directory + "\groupname\" + "Objects.ini"​

Hope you find the solution with this input.
 

camerakid

Member
Some ideas:

The line
ini_open(working_directory + "Objects.ini");​
should be correct. Afaik working_directory ends with a backslash. Just in case it doesn't: try
ini_open(working_directory + "\Objects.ini");​
On HTML5 target GM:S should convert any backslashes to slashes anyways so you don't have to worry about that however I don't know when that safety was implemented. So you might want to try:
ini_open(working_directory + "/Objects.ini");​

By now you should have your ini file in the included file ressource tree. If you made a group in the included files section and put a file in that group the file will be at:
working_directory + "groupname\" + "Objects.ini"​
or maybe with a blackslash but i think not:
working_directory + "\groupname\" + "Objects.ini"​

Hope you find the solution with this input.
Thanks I will test all these and give back a feedback :)

EDIT: none have seemed to be working... However it seems if I include "working_directory + "html5game/Objects.ini" sometimes it works...
 
Last edited:

chamaeleon

Member
I hope you're not expecting the ini file to be stored on the server from where your game is launched, ini on HTML uses browser local storage.. Anyway, it seems to me it should work just fine using ini_open("filename.ini"), do whatever you need to do with the ini file, followed by an ini_close() to make sure it gets saved (per documentation, every modification is kept in memory until ini_close(), so if you don't call it, all your changes are basically a big noop). I haven't seen any references to ini_close in your comments, but I hope you do include it at the end of ini operations. In any case, you shouldn't need to make use of working_directory.
 

camerakid

Member
Thanks for your answer... Of course I am closing with the ini_close() but can anyone finally explain me what and how it works?!

So basically there is game running on my server right? I open it in another computer in my browser. I click save game. Than it saves to the local storage of somewhere in the browser's directory. After that I close the window and the browser reopening it and refreshing the page. How can I load that game again? Will my browser know that this game has already been opened before and load from the browser's appdata?
 

chamaeleon

Member
Game is not running on server. It runs in the browser only, executed as JavaScript, using whatever JavaScript functions the ini calls are translated to in order to modify local storage to simulate the equivalent file operations had it been a Windows or Android program. The local storage, whose implementation may vary between browsers I suppose, persist across launches of the browser, and is the reason it is not shared between browsers and computers. All local within the confines of the browser on a computer. And yes, whatever your write should be possible to read in a subsequent start of the game in the same browser installation even if the browser or computer is restarted.
 
Top