Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / How to save files in HTML AGK version?

Author
Message
MMT
6
Years of Service
User Offline
Joined: 12th Mar 2018
Location:
Posted: 29th Mar 2020 18:12

How exactly can I write and read files when using the HTML version (saving on the server, saving locally)?

So, e.g. send your highscore to the server after playing the game. And then retrieving it back (not showing in the app)?

Thanks!
Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 30th Mar 2020 21:09 Edited at: 31st Mar 2020 16:16
I decided to use the OpenBrowser() command and send the variables with GET after generating a key to validate the data being sent.

If you scroll down about midway of this thread, then you will see a brief explanation of how it works.

You will need to know PHP to do one like I did, but it is not that hard and I learned as I went for that 6marbles example.

It sends the data to be stored in a simple flat on a website offering free hosting, without any files being saved locally.

Once on the server, the data can be viewed by any device via a webpage created by a separate PHP/HTML script that only reads the data for display.

So...

The Game send the script the variables at the end of the game using the OpenBrowser() command with variables passed with GET form method.

Then, the server PHP script checks to see if the key is a match and the data is valid.

Then, the script creates our array to hold the data while we process it. (default values initialized)

Then, the script checks to see if the file exists for that game title, and creates a file and/or opens it.

The data is read and loaded into the array if existed, all default values if created. (placement holder variable defaulted at 52)

We loop through the data and look for a match (same player/score/date), If a match we ignore and skip the other checks, else...

Then, the script reads the values backwards (descending) so we can check the placement of submitted score.

During loop if score is > we save placement value in a variable and replace the last row of data (loop r + 1) with this slots data and then replace this slots data with our submitted data.
This slot being each line/row of data consisting of three fields of data being the player name, the score, and finally the date (no need to store the keys or ranks/loop counter)
This is continued all the way up, so the shift of scores takes place all the way up. But nothing is written yet, just our array being modified.

At the end of the cycle we check that placement value as we display the results.
We also use that to determine if we need to update the data or not, as in the case of a tying score by the same player on the same day (refresh submission).
Since the placement part was avoided by the equal ignore, we know that our default value of 52 was not high enough for the leaderboard.
So, the old data was displayed and not the new. If a score is greater, then that trigger is was sets the placement value of that iteration of the loop.
So when that value is less than 51 at the end, then we know to display the new board with the placement position of the loop catching that for a background and font color change.
The rest of the iterations get the defaults colors and our record holder's position is displayed being highlighted.
That placement value can also be used for custom messages, like acknowledging a Champion or simply stating the Rank for that score.
If that placement value was less than 51, then we know we had updated data and we open the file and write over it with the updated array.
Then close the file, and The End.

Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1

Login to post a reply

Server time is: 2024-04-25 17:06:00
Your offset time is: 2024-04-25 17:06:00