Is there a way to put a hit/play counter onto the actual page to show how many people have loaded the game/webplayer? Possibly adding +1 to the counter whenever a function is called from a script in the game.
Not that I know of. You could just put a webpage hit counter on the HTML page the web player is embedded in. It would give you a rough estimate on amount off plays.
For regular hit counters I saw that there were GoStats.com and StatCounter.com but I wanted something a bit more specific. People could easily refresh the page over and over and make the hit counter go up. I’d like a function from the game to be called so it would insure that the hit counts for when the webplayer was actually loaded.
Maybe you could do it through an SQL database? I am not too familiar with SQL if I’m honest, but you should be able to do something like this. function runs > sends +1 to database table > display the number held in that table on the webpage or in the web player itself.
There are some SQL assets on the asset store.
Just write a simple php function saving the hit counts to a simple txt file on the server and invoke that from Start function inside the webplayer.
I looked up about the SQL database and it seems a bit complicated. I’ll see what it takes to do php. If I can store a txt file in the same location as the webplayer and can make some code that accesses it then that’d be great!
It’d be easier to use a SQL database. This should roughly be the right code, though I’m not testing it. Just tell me if there’s any errors.
Create a new table in your database. Name it whatever you want, probably just plays.
This table needs to have two (2) fields.
Field 1: NAME: plays - TYPE: INT - DEFAULT: 0
Field 2: NAME: id - TYPE: INT - DEFAULT: 1

Now go to the insert tab. We are gonna insert a row in the table, this will be what keeps track of the plays for you.

Now if you go to browse, you should see a table with plays and ID, like this.

Now, this PHP script should work. I’m about 90% it will.
This is how it works: name it plays.php. Edit the database values I have at the top to coordinate with your server. After that, upload the file to your server.
http://WEBSITE/PATH/plays.php - this will display the amount of plays your game currently has
http://WEBSITE/PATH/plays.php?update=1 - this will add one play to your database. The 1 is irrelevant, it can be anything, but something HAS to be there to update it
<?php
//Set these to your SQL standards. Host is likely just localhost.
$database = mysql_connect('SQL HOST', 'SQL USER', 'SQL PASS') or die('Could not connect: ' . mysql_error());
//SQL DATABASE NAME is the name of your DATABASE, not the TABLE
mysql_select_db('SQL DATABASE NAME') or die('Could not select database');
//Name of the table you're editing - probably "plays" in this case
$table = "SQL TABLE NAME";
//I'm making it so that you have to have to tell it to update it, so you can access this file without adding to it (IE: to get the string of how many plays you have in game
if (isset($_GET['update'])) { //If the url is plays.php?update=1 , then you will update the amount of plays
$query = "UPDATE $table SET plays = plays + 1 WHERE id=1";
mysql_query($query) or die('Query failed: ' . mysql_error());
} else { //if it isn't set, your plays will be displayed
$query = "SELECT * FROM $table WHERE id=1";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$number_rows = mysql_num_rows($result);
echo($number_rows[0]);
}
?>
Now in your game, create a new javascript file. Here you go.
If you do the addPlay() function, like at the begining of your game, it will add a play to the database.
If you do the getPlays() function, it will load how many plays the game has, and set the plays string to that number.
var plays : String; //When you use the getPlays() function, this will turn into how many plays your game has
var urlOfPlays : String; //Edit this in the navigator to your full URL to the plays.php file
function addPlay() {
//This will add a play to your database
var addplay = urlOfPlays + "?update=1";
var addplay_load = WWW(addplay);
yield addplay_load; // Wait until the download is done
if(addplay_load.error) {
print("There was an error adding plays: " + addplay_load.error);
} else {
print("Play added.");
}
}
function getPlays() {
//This will add a play to your database
var getplay = urlOfPlays;
var getplay_load = WWW(getplay);
yield getplay_load; // Wait until the download is done
if(getplay_load.error) {
print("There was an error retrieving plays: " + getplay_load.error);
} else {
plays = getplay_load.text;
print("Total plays: " + plays);
}
}
Hope it works
Is there any free SQL server that you would recommend. Maybe a way to use dropbox as one? I’ve never had to deal with such things before.
http://www.000webhost.com/ appears to have what you need. No way to use dropbox