Implementing High Score Saved to file table of DB

Monkey Forums/Monkey Beginners/Implementing High Score Saved to file table of DB

probson(Posted 2017) [#1]
Hi,

My students are making games and so far have done it for HTML 5. What they need next steps are when the game ends asking the high score and then saving this into possible a CSV file, a DB or an online database.

What is the best way for them to do this? In terms of handling the data they need to show that once they get the data from the source that they use a common sorting algorithm like a merge sort or quick sort for that data.

Is HTML 5 going to cut it or do I need to move their projects across to GL2? I have so far avoided this as in school no EXE's are allowed so has to be run in a virtual machine.

Any help greatly appreciated so I can teach my students approaches and then they can pick best one for them and their projects.

Thanks,

Paul


semar(Posted 2017) [#2]
Hi Paul,
as far as I know, you can save and read a file from within a Html5 app written with Monkey.

Once read the file for example to a List, you could sort it as you like.

Bare in mind that the file you write/read, is located on the machine where the Html5 resides. In other words, if the Html5 game resides on a remote Server, then the high-score file will be the same for all the gamers. This is the ideal case.

If the Html5 game resides on different PCs, then you have more high-score files that differ each other.

Alternatively, there are Html commands that helps to dialog with a php script on a remote webserver, and you could program the server side (PHP) code in order to deliver a list of high score and nicknames, and show it sorted from within your html5 app/game.

Hope this helps,
Sergio


probson(Posted 2017) [#3]
Hi Semar,

I know this is asking alot but do you know where there any examples of this or not?

If you use a list can you still refer to a line then look at say position 1.

So if list has name 10 as an example can you do this easily like in other languages and just sort using that column?

Thanks,

Paul


semar(Posted 2017) [#4]
Hi Paul,
yes I guess you can sort as you like, you may use a string format that allows you to sort as you expects.

You could have a List of objects for example; the List index is the score, and the object is a string containing the nickname.

When you sort the list against the score, you may get what you' re looking for.


semar(Posted 2017) [#5]
As for references for Filestreams:
http://www.monkey-x.com/docs/html/Modules_brl.filestream.html#description

Lists:
http://www.monkey-x.com/docs/html/Modules_monkey.list_StringList.html


Xaron(Posted 2017) [#6]
I once did it for a game of mine: http://www.krautapps.com/games/shapemaster/

Click at highscore to see it. It uses a PHP/MySQL backend. I could post the code here if you like? It's somehow even "hardened" against cheat attempts using hashes and keys...


probson(Posted 2017) [#7]
If you had the code for that it would be great. I showed one of my students and said would he have the code he did for the buttons as well and I said I would ask.

PHP/MySQL would be great for their projects as shows more complexity integrating that in.

Thanks,

Paul


Xaron(Posted 2017) [#8]
Right, I've uploaded the complete game here: https://github.com/KrautApps/ShapeMaster

You need fontmachine to compile it which you can get here: http://www.jungleide.com/?page_id=5179

Plus there is a pimped httprequest file within the monkey folder where I added stuff like timeouts to the requests. You have to overwrite the original brl stuff with this one.

The files in the server folder have to be uploaded to the webserver, then execute that database.sql file to create the database structure. Oh and you have to look into these and set your database name and password accordingly of course.

The main entry is eyeballing.monkey or open the project using Jungle IDE if you have.

Let me know if you have any specific questions. :)