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/AppGameKit Studio Showcase / [AGK] Purple Token library (online hi-scores)

Author
Message
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 15th Nov 2023 05:08 Edited at: 11th Dec 2023 18:22
I've added a new feature to the REST api for purpletoken, retrieving the submission dates of scores. Just add "dates=yes" to your POST variables when retrieving scores. I've also written a simple to use library that should hopefully take some confusion out of using the hi-score online service. If you don't yet have a game key, you can register for an account here: https://purpletoken.com/register.php

Updated with Psy's corrections and also added a new error code to capture when a score submission fails due to being too low (if all 20 slots are full).

The library:



Example:




You can get creative with your high score display!
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda
Pixel-Perfect Collision

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

PSY
Developer
7
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 25th Nov 2023 23:47
Awesome
Thank you for your continued work on this great project!

PSY


PSY LABS Games
Coders don't die, they just gosub without return
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 26th Nov 2023 21:17 Edited at: 26th Nov 2023 21:41
Phaelax had this tucked in Code Snippets but it deserves a bigger stage where more people need to utilize it where it's opened up a number of doors for me and can extend the life, audience and general FUN of a game so easily.

make sure to check out the FAQ which does subtly mention a max 32 characters for a player name which can be considered a general unique string that you can use to contain not only a player name or initials but other data as well by using delimeters.

ie, in LoS, i wanted to include the LOCAL date for the player when the score was submitted vs PT's server date as well as a unique Session ID that i can use to purge some scores as a user climbs the ladder without worrying if it was another user with the same initials so the "player" string is crafted and submitted, as follows using the pipe | delimeter:


then to display the data, i can pull the initials and date from the "player" string via GetStringToken() (and add commas to the score for display):


plenty of room to get creative there, too. ie, how about including a player's custom color inside, or something else? for that matter, who says the system can only be used for high scores?

regardless, phaelax is offering lots of potential with this. i'm sure LoS couldn't have reached nearly 400 browser sessions** in 2-3 weeks if there weren't live high scores and a global ladder to climb which extends replayability for it so THANKS for that!

also worth mentioning: since bytecode will leave literal strings inside as human-readable, you should obfuscate your game key(s) using something as simple as THIS (Phaelax-approved method), or some other means.

**btw, yes. the AppGameKit commands necessary to use the server DO function fine in HTML exports.
PSY
Developer
7
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 27th Nov 2023 21:51 Edited at: 11th Dec 2023 01:40
@Phaelax
In the library, there should be the following code between line 104 and 105:

Without it, an error will be thrown at line 94 if you use SetErrorMode(2)


PSY


PSY LABS Games
Coders don't die, they just gosub without return
PSY
Developer
7
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 11th Dec 2023 15:55 Edited at: 12th Dec 2023 17:01
Hey,

I played around a bit and found an issue in the library in line 102:

This line must be removed, otherwise the return code after a score submission will always be 1 ( success ), no matter if the character limit of 32 was exceeded or the gameKey was not recognized.

I made some minor changes so the library works with #option_explicit, and also added 2 functions that simply check if there is an active submit or request connection, so that a new submission/request is only made if there are no active connections open.

EDIT: Updated to newest version on 12/12/2023

Here's the updated library:


Here's an example code where you can submit a legit score, submit a score with an invalid name, and request the score table. You just need to enter your gameKey.


PSY


PSY LABS Games
Coders don't die, they just gosub without return
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 11th Dec 2023 17:06 Edited at: 11th Dec 2023 17:07
thanks for posting, PSY. i've been trying to sort out an issue with the original code (pre-current library) and only caused more errors. i NEED to get this running without issue and you just saved me a ton of time
PSY
Developer
7
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 11th Dec 2023 17:33
You're welcome, glad I could help


PSY LABS Games
Coders don't die, they just gosub without return
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 11th Dec 2023 18:20
Thanks Psy, a few minor oversights. I've also updated the server and added a new error code. Submitting a score that was too low for the top 20 would result in -1 (unknown) error, so I've fixed it to return 4 instead.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda
Pixel-Perfect Collision

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

PSY
Developer
7
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 11th Dec 2023 21:44
Quote: " I've also updated the server and added a new error code. Submitting a score that was too low for the top 20 would result in -1 (unknown) error, so I've fixed it to return 4 instead."

Nice, thanks alot Phaelax !


PSY LABS Games
Coders don't die, they just gosub without return
PSY
Developer
7
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 11th Dec 2023 22:02
I forgot to mention another change I made:

The code block In you example line 48-55


should rather be


Otherwise, the code will crash ( array out of bounds ) if submitCode is -1


PSY LABS Games
Coders don't die, they just gosub without return
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 12th Dec 2023 03:49
Yea I made that change as well, I just didn't update the example. Frankly, when i turned on explicit it broke everything. Even after defining variables it still insisted they weren't defined. So I said screw it and left my house lol
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda
Pixel-Perfect Collision

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

PSY
Developer
7
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 12th Dec 2023 16:49
Quote: "Frankly, when i turned on explicit it broke everything. Even after defining variables it still insisted they weren't defined."

Can't be much, probably something got mixed up because I renamed some variables or any other minor oversight.
Or maybe because I worked with .length as Dim doesn't work that way inside functions with #option_explicit.

Quote: "So I said screw it and left my house lol"

I hear you





PSY LABS Games
Coders don't die, they just gosub without return

Login to post a reply

Server time is: 2024-04-27 17:33:04
Your offset time is: 2024-04-27 17:33:04