Page 1 of 1

Livecode Multiplayer Leaderboard

Posted: Mon Jun 21, 2021 3:01 pm
by FESEFW
I am trying to make an online multiplayer leaderboard, I've searched for it all over the internet and I only found one thing that's in the forums and its links doesn't work anymore because it's from 2014.
Please help,
Fest

Re: Livecode Multiplayer Leaderboard

Posted: Mon Jun 21, 2021 3:43 pm
by bogs
Hello Fest, could you perhaps give a bit more information about what exactly you are trying to create? For instance, a picture would be helpful, but, lacking that, maybe a short textual form describing what you want as far as looks and functionality go?

The following is an example:

Are you looking for something like this display wise...
Image

Or something more like this....
Image

Or something altogether different?

What information are you looking to display? Does someone need to be logged in to view it? Something else altogether?

Re: Livecode Multiplayer Leaderboard

Posted: Mon Jun 21, 2021 6:03 pm
by FESEFW
Hi Bogs,
Thanks for answering so fast,
I am trying to make something like shown in the second picture. I already own a MySQL server that I'm controlling on phpMyAdmin. Also, in the game main screen, I programmed a 'name pick' button which you can pick your name into global _PlayerName.
Thanks,
Fest

Re: Livecode Multiplayer Leaderboard

Posted: Mon Jun 21, 2021 6:53 pm
by bogs
Ok, now we have a look your shooting for, while I don't normally recommend this route, it looks like what your shooting for would be a good fit for a form version of a datagrid.

I *think* this lesson should get you started nicely on creating the form style grid you want-
https://lessons.livecode.com/m/datagrid ... -of-people


In your OP you mentioned this would be online, which I am guessing means you store the information online and want the data read back into the application run locally. That part of it (I would hope) some others that do stuff along those lines would chime in for, but I don't foresee any great difficulty in accomplishing it.

Re: Livecode Multiplayer Leaderboard

Posted: Mon Jun 21, 2021 7:37 pm
by FourthWorld
FESEFW wrote:
Mon Jun 21, 2021 3:01 pm
...I only found one thing that's in the forums and its links doesn't work anymore because it's from 2014.
Unlike most languages, LC has an uncommonly good track record of maintaining backward compatibility. Where is that earlier discussion, and what part of it didn't work?

Re: Livecode Multiplayer Leaderboard

Posted: Tue Jun 22, 2021 6:22 am
by FESEFW
bogs wrote:
Mon Jun 21, 2021 6:53 pm

In your OP you mentioned this would be online, which I am guessing means you store the information online and want the data read back into the application run locally. That part of it (I would hope) some others that do stuff along those lines would chime in for, but I don't foresee any great difficulty in accomplishing it.
Thank you so much!

Re: Livecode Multiplayer Leaderboard

Posted: Tue Jun 22, 2021 6:28 am
by FESEFW
FourthWorld wrote:
Mon Jun 21, 2021 7:37 pm
FESEFW wrote:
Mon Jun 21, 2021 3:01 pm
...I only found one thing that's in the forums and its links doesn't work anymore because it's from 2014.
Unlike most languages, LC has an uncommonly good track record of maintaining backward compatibility. Where is that earlier discussion, and what part of it didn't work?
For some reason I can't send links

Re: Livecode Multiplayer Leaderboard

Posted: Tue Jun 22, 2021 8:06 am
by FourthWorld
Does it have a title? What section is it in?

Re: Livecode Multiplayer Leaderboard

Posted: Tue Jun 22, 2021 9:38 am
by SparkOut
Guessing it's this one viewtopic.php?f=22&t=19380#p99792

I'm not sure exactly what you would find in the original stack

Re: Livecode Multiplayer Leaderboard

Posted: Tue Jun 22, 2021 2:45 pm
by ClipArtGuy
The high score board of that space shooter stack was powered by a simple mysql database. From my memory it was basically just two columns - name/score.

edit: I'm not exactly sure how helpful this is, but that stack was definitely using a simple mysql database with a table named "highscores" with two columns "name" and "score". I dug this stack out and copied the relevant script, but you should definitely NOT do it this way. It is way more secure to put a script like this on your server as middleware, than to hard code the credentials/functionality into your app itself.

Code: Select all

global AMiConnected
   
   put "yourSQLhosthere" into vScoreDatabaseHost
   put "yourDataBaseNameHere" into vDataBaseName
   put "yourDataBaseUserHere" into vDataBaseUser
   put "yourDataBaseUserPasswordHere" into vDatabasePassword
   put revOpenDatabase("MySQL", vScoreDatabaseHost, vDataBaseName, vDataBaseUser, vDatabasePassword) into tResult
   
   
   if tResult is a number then
      put tResult into AMiConnected
      put "HighScores" into vScoreTable
      put "Name,score" into vNewPlayerInfo
      put fld "score" into vPlayerScore
      put "INSERT INTO " & vScoreTable & " (" & vNewPlayerInfo & ") VALUES (:1, :2)" into tSQL
      revExecuteSQL AMiConnected, tSQL, "vPlayerName", "vPlayerScore"
      put "HighScores" into vScoreTable    
      put "SELECT * FROM " & vScoreTable into tSQL
      put revDataFromQuery(tab, cr, AMiConnected, tSQL) into ScoreData
      if item 1 of ScoreData = "revdberr" then
         answer error "Unable to post high score" 
      else
         put ScoreData into field "Data"
         sort lines of fld "data" descending numeric by word 2 of each
         replace"_" with " " in fld "data"
         repeat with w= 11 to the number of lines in fld "data"
            put empty into line w of fld "data"
         end repeat
         repeat with p=1 to the number of lines in fld "data"
            put (p&".") before line p of fld data
         end repeat
         set the textcolor of line 1 of fld "data" to green
         
      end if
      if AMiConnected is a number then
         revCloseDatabase AMiConnected
         put empty into AMiConnected
      end if
   end if

Re: Livecode Multiplayer Leaderboard

Posted: Tue Jun 22, 2021 4:05 pm
by FourthWorld
Does the leaderboard show the scores of all players, or just the leaders?

If the latter, does it need a database? Might a simple text file do?

Re: Livecode Multiplayer Leaderboard

Posted: Tue Jun 22, 2021 4:27 pm
by ClipArtGuy
FourthWorld wrote:
Tue Jun 22, 2021 4:05 pm
Does the leaderboard show the scores of all players, or just the leaders?

If the latter, does it need a database? Might a simple text file do?
I guess I had assumed that multiplayer leaderboard meant there would potentially be multiple concurrent users (who may try to save their high score) at any given time.

Re: Livecode Multiplayer Leaderboard

Posted: Tue Jun 22, 2021 5:56 pm
by FourthWorld
ClipArtGuy wrote:
Tue Jun 22, 2021 4:27 pm
I guess I had assumed that multiplayer leaderboard meant there would potentially be multiple concurrent users (who may try to save their high score) at any given time.
The moment of writing to disk is rarely if ever truly concurrent. The question is how we handle the need to momentarily lock that part of the storage file.

When what's being stored is small, locking the entire file may cost less than a single millisecond.

MySQL's InnoDB storage engine locks at the record level, and its MyISAM engine locks entire tables.

Combined with the overhead of both IAC and LC's externals interface, not to mention the internal b-tree traversal, sometimes locking a small flat file is more efficient.

Little things add up, and using a relational DB engine involves *lots* of little things.

And then there's development and maintenance time...

Re: Livecode Multiplayer Leaderboard

Posted: Wed Jun 30, 2021 12:59 am
by mtalluto
Years ago, we made a sample game that demonstrated how to store a player's score and generate a High Score Leaderboard.

The game is written in LiveCode and uses LiveCloud for the backend. The code is simple to read and easy to port to another database.

You can see a quick demo of it on youtube:
https://www.youtube.com/watch?v=wjXHt8MqYNY

Feel free to download the working code here:
https://www.livecloud.io/downloads/Dropper/Dropper.zip

*Please note that this code requires a paid edition of LiveCode because it relies on encryption features found in Indy or Business.

** You do not need a LiveCloud account to play.