Highscores script.

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
ljdp
Party member
Posts: 209
Joined: Sat Jan 03, 2009 1:04 pm
Contact:

Highscores script.

Post by ljdp »

I've made a quick highscores script that's nice and easy to implement into your game.
Made from simple PHP, MYSQL and lots of love. :ultrahappy:
highscore.lua
Highscore.lua version 2
(7.41 KiB) Downloaded 212 times
How to use it

Code: Select all

highscore.init( "Game name" )
-- Place this into your load function.
-- "Game name" : A unique name for the highscore database.

highscore.add( "gamename", "name", score )
-- Adds a score to your highscore.
-- "Game name" : A unique name for the highscore database.
-- "name" : Name to add.
--  score : Score to add.
-- Returns true if added, false if there was an error.

highscore.get( "gamename", ascending )
-- Downloads the current highscores for your game.
-- "Game name" : A unique name for the highscore database.
-- Ascending: set to true if you want the scores in ascending order.
-- Returns a table of the highscores if you wish to draw them yourself.
-- The table is in the following format:
-- table[1].score = highest score.
-- table[1].name = name of the highest score.
-- table[n] ... and so on in decending order.

highscore.draw( x, y )
-- Put this in the draw function. This won't draw the highscores until you
-- call highscore.show(). When you do it will draw the highscore with previous and
-- next buttons and a close button.
-- x,y for position.

highscore.show()
-- Starts showing the highscores.

highscore.hide()
-- Hides the highscore.

highscore.fancyadd( "gamename", score, ascending )
-- Shows a box asking the player for their name. When they press
-- submit it will upload the score then download and show the highscore list.
-- "Game name" : A unique name for the highscore database.
-- Score: score to add.
-- Ascending: set to true if you want the scores in ascending order.

highscore.keypress(key)
-- If you're going to be using the fancyadd function you need to put
-- this function in the keypress function so the player can type their name.
-- Key: the key variable in the keypress function.

You will need a unique gamename as all the highscores are stored in a single table.
You can see a list of gamenames in use here to check for conflicts.
Please note this isn't secure at all. But i'm pretty sure fellow LÖVErs aren't of the corrupt type. :)
Last edited by ljdp on Mon Jun 08, 2009 4:20 pm, edited 2 times in total.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Highscores script.

Post by bartbes »

Looks nice..., but
ljdp wrote:Please note this isn't secure at all. But i'm pretty sure fellow LÖVErs aren't of the corrupt type. :)
you forgot about me.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Highscores script.

Post by Robin »

Pretty cool. Using a public highscore dumping place has it's disadvantages though. Especially name collisions. If two people both name their game "coolgame", their highscore list will be polluted. (Of course, a simple way to overcome this is to use a unique ID. Maybe a hash of some sort.)
Help us help you: attach a .love.
User avatar
ljdp
Party member
Posts: 209
Joined: Sat Jan 03, 2009 1:04 pm
Contact:

Re: Highscores script.

Post by ljdp »

Well that's not too much of a problem.
Here's a quick php to list all the games in use.
http://locofilm.co.uk/highscore/list.php
User avatar
ljdp
Party member
Posts: 209
Joined: Sat Jan 03, 2009 1:04 pm
Contact:

Re: Highscores script.

Post by ljdp »

Just made an example using the 'no' demo that comes with love.
By just appending a number to the end of the highscore gamename you can have seperate highscores
for each size of grid.
I've added some stuff to the highscore.lua such as highscore.fancyadd() which shows a box asking for their name
uploads the score, downloads the highscore and shows em all in one function.
So i'll upload that in a bit.
no-with-highscores.love
No with highscores
(286.41 KiB) Downloaded 146 times
User avatar
Sparx
Party member
Posts: 125
Joined: Thu Apr 02, 2009 9:54 am
Location: Aachen, Germany

Re: Highscores script.

Post by Sparx »

php-code would be nice to....
User avatar
ljdp
Party member
Posts: 209
Joined: Sat Jan 03, 2009 1:04 pm
Contact:

Re: Highscores script.

Post by ljdp »

Sure,
Php-highscore-scripts.zip
Php scripts
(1.07 KiB) Downloaded 150 times
Just put in your hostname, user, password and db name.
Also on your mysql create a table called 'highscores' with the rows:
game - varchar
name - varchar
score - int

I use a size of 10 on all of them to limit space usage.
You will also need to find and edit the parts in highscore.lua that connects to the php scripts.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Highscores script.

Post by bartbes »

How did it know my 44 secs on no was better than 66? (basically, how does it know which way to sort?)
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Highscores script.

Post by Robin »

In get.php:

Code: Select all

$up   = $_GET['up'];

(snip...)

if ($up = 1)
{
$qry = "SELECT name, score FROM highscores WHERE game='$game' ORDER BY score";
}
else
{
$qry = "SELECT name, score FROM highscores WHERE game='$game' ORDER BY score DESC";
} 
So I think that means $up is passed via the url.
Help us help you: attach a .love.
User avatar
ljdp
Party member
Posts: 209
Joined: Sat Jan 03, 2009 1:04 pm
Contact:

Re: Highscores script.

Post by ljdp »

Yeah
highscore.get( "gamename", ascending )
the ascending sends the $up var.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 221 guests