Cross platform leaderboardDemo
scottharrrules43
Tulsa, OklahomaMember, PRO Posts: 694
This template is used for server leaderboards. This is a template i made from a game I published to the app store. It has been modified for other peoples use. Just plugin your own server info into the GetURL and SendURL and your off.
Edit: you will need edit the upload button to include your own score attribute.
Comments
Wow! Thanks for sharing!
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx
Thanks for sharing scottharrrules43! I am just starting to learn leaderboard. So this helps greatly.
Big Smile Games Play Happy!
Check out our other GameSalad exclusives.
The curse word remover is awesome!!!!! Makes for a kid friendly environment.
Big Smile Games Play Happy!
Check out our other GameSalad exclusives.
Yeah I add that in my game and to lazy to remove it. Could come in handy if you don't want jerks putting bad words on your servers. I put way to much work into it than I should have so just be warned when editing.
Yeah, I am looking through the code know. It's pretty robust. However it will be very useful. Thanks again for sharing.
Big Smile Games Play Happy!
Check out our other GameSalad exclusives.
here is php stuff
(thanks to @jonmulcahy)
This is scraped together, so it may not work (fingers crossed).
Now the only thing left is creating your own server.
I used and it is free.
https://byethost.com/index.php/free-hosting .
I will give it a try. Thanks!
Big Smile Games Play Happy!
Check out our other GameSalad exclusives.
Hi! I used the php file in get.zip and it works fine but when I use it in another project I get a -1 for failed connection. Please help.
Did you make sure the send and get url are right?
What did it fail on the get or send?
Also what are you hosting with, it may be down 000webhosting is not working for me.
Hi I used the get.php and it works great. I tried the send.php and I get a "}" when I call it in the browser. Is this correct? As before I use this url in Gamesalad but it doesn't work.
Any help?
Cheers
first of i tried to download my code to try test it and there are \\\ everywhere, i don't know why? So I am now using google drive for php storage I recommend using this to get php files.
https://drive.google.com/folderview?id=0B5swSg-cH4L6fndhSUk5UW9wTE1Rb1lvUy03UTNQVWRjRnhuZlJlQnR2YWNNeXVVcW9Nb1E&usp=sharing
if your download the project from google drive go to line 71&74 of get.php and change id453417 to your table id(I will show your how in a second)
important note: on line 71 id453417_headers, on keep the _headers at the end of your table id.
If a table id right click your gamesalad project->show packaged content
then find table folder and bam there they are. Grab your table id which is id(some number)
(don't include .xml)
try new php files in link above
I did the get and send url right, changed the table id everything but when I use the network get behavior the output is always -1 which is a failed connection. This happens when I use it in other projects. It only works in the project I first used it but when used in other projects with the table id changed it does not work. Thanks
Remember you also have to change the host, table, and database stuff if you're not using the same info in all your projects.
So the Send.php makes a correct json.txt but I also get the sqlErrors.txt, Error writing to database/
Also, like stated before it only displays a "}".
Remove the highlighted regions if your table does not contain the row labeled "auto_i."
Does anyone have a game up with this leaderboard in it? If so share
Thanks @RabidParrot I don't use Gamesalad much more I moved on.
Edit: fixed google drive php docs modified.
@tappwater Games
It is alpha but it works
https://appsto.re/us/SLWo3.i
Need help with the send php. When I use the send php my browser was blank and the callback attribute in gamesalad was 0 even though the variables are correct and the data in the database was also not changed. I did the send php just like the get php without the table ID. Is what I did correct? if no please help.
Thanks for the help with my first problem.
what does your table look like?
I did just like what is in the php file.
This one is the database table.
Looks like you've missed naming your columns in the table. Try that and see if it works
Nope still nothing. I didn't change anything in the php file except for the servername,username,password,dbname and the tablename. It connects to the database but still nothing happens.
I use byethost.com as my database but when I run the php file nothing appears in the browser.
try using get new send.php file(1.1.2)
just add 2 seconds ago
guess there was } hanging out.
Nope still nothing.
Here is my php file. I created a new database with table name Values with playerID, playerName and playerStats as columns.
<?php //1.1.2 // connect to SQL $servername = "sql203.byethost17.com"; $username ="b17_16399865"; $password = "*******"; $link = mysql_connect($servername, $username, $password); // database connection strings. change these to your DB and Table names. $dbName = "b17_16399865_TEST5"; $tableName = "Values"; if (!$link) { //exit('Error: Could not connect to MySQL server!'); echo mysql_errno($link) . ": " . mysql_error($link). "\n"; } // connect to the table\ mysql_select_db($dbName)or die("cannot select DB"); // lets prepare some files to capture what is going on. $incomingJson = 'json.txt'; //$fullArray = 'fullArray.txt'; // needed if you enable the debugging secton below\ $sqlErrorLog = "sqlErrors.txt"; // initialize the string with a blank value $string = ""; // start SEND data\ if ($_SERVER['REQUEST_METHOD'] === 'POST') { //capture incoming data error_reporting(1); $sig = $_POST["sig"]; $jsondata = $_POST["params"]; // this line captures the sent data so you can figure out what you need to send back.\ file_put_contents($incomingJson,$jsondata); // this line tells the application that the data send was successful.\ echo '{"Status":"Success"}'; // convert JSON to an array\ $array = json_decode($jsondata, TRUE); /* // formats the array to view it easier\ $results = print_r($array,true); file_put_contents($fullArray,$results);\ */ //get the total number of objects in the array\ $arrlength = count($array['Children']['1']['Properties']); // set while loop index\ $i = 0; //loop through array node and get row values\ while ($i < $arrlength ) { // get row value\ $value = $array['Children']['1']['Properties'][$i]['Value']."\n"; // convert delimited string to an array\ $arrayPieces = explode("|", $value); // get array values. This section would have to be modified to capture each value you are interested in.\ $rowName = $arrayPieces[0]; // this variable will be blank if you don't name your rows. \ $playerID = $arrayPieces[1]; $playerName =$arrayPieces[2]; $playerStats = $arrayPieces[3]; // construct SQL statement\ $sql="INSERT INTO ".$tableName."(playerID, playerName, playerStats)VALUES('$playerID', '$playerName', '$playerStats')"; // insert SQL statement\ $result=mysql_query($sql); // catch any errors\ if($result){ // if successful do nothing for now.\ } else { // if failure, write to custom log\ $sqlError = "Error writing to database\n"; file_put_contents($sqlErrorLog, $sqlError, FILE_APPEND); } $i++; } } // end of POST\ // close the SQL connection\ mysql_close($link); ?>
This is the behavior in gamesalad. The table values are the same same as my last post. I added column names but still nothing happened.
http://capstoneproject.byethost17.com/C.php
This is my php link.
Thanks for the help. I am new to gamesalad and I appreciate all your help.
Are you producing an error file?
Is your d
Ok so i see your gamesalad table values to the left. So does your database look like this
https://www.dropbox.com/s/6c7uw2l2adhk6aq/Screen Shot 2015-07-25 at 11.32.51 PM.png?dl=0&s=sl
it does not matter what you name your rows or columns in gamesalad (in this case at least) what matter is what your table name is in this case.
Basically what is your database table name? it should be "Values"
also as @RabidParrot said what is error text say?
Nope. There was no error file.
Also changed the table name in gamesalad to "Values". Still nothing.
I followed along with this video collection; five in total.
and all worked great.
Follow or browse the steps. There are a few parts that need doing just right ... like where to place the .php files.
Hope this helps
Valan
I really appreciated the sharing from scottharrrules43.
At beginning, I also could not get sent.php working. it was stuck in json_decode due to "slash" issue in $jsondata = $_POST["params"];
******slash issue of my case********
{\"Properties\":[],\"Name\":\"\",\"Children\":[{\"Properties\":[{\"Name\":\"rowCount\",\"Value\":3},{\"Name\":\"columnCount\",\"Value\":3},{\"Name\":\"0-1-name\",\"Value\":\"PlayerID\"},{\"Name\":\"0-1-type\",\"Value\":1},{\"Name\":\"0-2-name\",\"Value\":\"PlayerName\"},{\"Name\":\"0-2-type\",\"Value\":1},{\"Name\":\"0-3-name\",\"Value\":\"PlayerStats\"},{\"Name\":\"0-3-type\",\"Value\":2}],\"Name\":\"id758931_headers\",\"Children\":[]},{\"Properties\":[{\"Name\":\"1\",\"Value\":\"1|aaa|bbb|0|\"},{\"Name\":\"2\",\"Value\":\"2|fff|dd|0|\"},{\"Name\":\"3\",\"Value\":\"3|ddddggg|www|0|\"}],\"Name\":\"id758931\",\"Children\":[]}]}
*******slash issue of my case*******
I found a solution from StackOverflow: Using JSON decode PHP 5.3.
It seems PHP Ver5.3 can't process these slashes with json_decode.
Therefore: I changed
$array = json_decode($jsondata, TRUE);
to
$array = json_decode(stripslashes($jsondata), TRUE);
then Json_decode works normally. Finally all data is now sent ....successfully to my server.
by the way, I also removed "auto_i" stuff from send.PHP in my case. Please check dated 7/21 post about auto_i removal.
Steven
Hi, I have used the get.php file and followed the tutorial as well by FunLearningGames. Everything went well until the last part, in which he was testing the connectivity of the server. I had hit a -1 and I've tried to replay the videos and even tried to fix it myself, but nothing seems to work... Here is my .php code. I may have done something wrong with it... I was wondering if you can be able to find the problem. The set attribute types, in order, are INT, Text, Text.
<?php // connect to SQL $servername = "sql104.byethost16.com"; $username = "b16_17276372"; $password = "**********"; $link = @mysql_connect($servername, $username, $password); // database connection strings. change these to your DB and Table names. $dbName = "b16_17276372_gsTest"; $tableName = "gsTest"; if (!$link) { //exit('Error: Could not connect to MySQL server!'); echo mysql_errno($link) . ": " . mysql_error($link). "n"; } // connect to the table mysql_select_db($dbName)or die("cannot select DB"); // lets prepare some files to capture what is going on. $incomingJson = 'json.txt'; //$fullArray = 'fullArray.txt'; // needed if you enable the debugging secton below $sqlErrorLog = "sqlErrors.txt"; // initialize the string with a blank value $string = ""; // start GET data if ($_SERVER['REQUEST_METHOD'] === 'GET') { // initialize the JSON body variable $jsonBody=""; // get table contents $query = mysql_query("SELECT * FROM ".$tableName); // construct an array to hold the data we pull from mySQL $rows = array(); // loop through the table and drop the data into the array while($row = mysql_fetch_assoc($query)) { $rows[] = $row; } // get the number of rows in the array. We need this in the JSON return $arrlength = count($rows); // set while loop index $i = 0; //loop through array node and get row values while ($i < $arrlength ) { // tables we are capturing $playerID = $rows[$i]['playerID']; $Username =$rows[$i]['Username']; $Password = $rows[$i]['Password']; $auto_i = $rows[$i]['auto_i']; // table row numbers. our index starts at 0, so we want to increment it by 1 to get valid row numbers. $tableRow = $i+1; // construct the JSON return from our data $jsonString = '{"Name":"'.$tableRow .'","Value":"|'.$playerID.'|'.$Username.'|'.$Password.'|'.$auto_i.'|"},'; // append the JSON return with the new data $jsonBody=$jsonBody.$jsonString; // increase index and loop again if not at end of array. $i++; } // construct the JSON response // this is the header of the JSON return. It will have to be adjusted to match whatever your app is expecting. We have to define this here to get the row count above. $jsonHeadher='{"Properties":[],"Name":"","Children":[{"Properties":[{"Name":"rowCount","Value":'.$arrlength.'},{"Name":"columnCount","Value":3},{"Name":"0-1-name","Value":"playerID"},{"Name":"0-1-type","Value":1},{"Name":"0-2-name","Value":"Username"},{"Name":"0-2-type","Value":1},{"Name":"0-3-name","Value":"Password"},{"Name":"0-4-type","Value":2},{"Name":"0-4-name","Value":"auto_i"},{"Name":"0-3-type","Value":2}],"Name":"id337760_headers","Children":[]},{"Properties":['; // this is the footer of the JSON return. Again it will have to be adjusted to match whatever your app is expecting. $jsonFooter='],"Name":"id337760","Children":[]}]}'; // removes an extra comma that the loop above leaves behind $jsonBody=rtrim($jsonBody, ","); // constructing the full JSON return $returnedJson=$jsonHeadher.$jsonBody.$jsonFooter; // write the JSON data so the app can read it. echo $returnedJson; } // end of get // close the SQL connection mysql_close($link); ?>}
Great help. Thanks. I have gotten the send.php to work in creator. It sends the table data to byethost perfectly, but once I test this on my phone it does not work. Can anyone help with this? Or does this only work in creator?