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 Classic Chat / Online High Score Table

Author
Message
The Daddy
15
Years of Service
User Offline
Joined: 13th Jan 2009
Location: Essex
Posted: 27th Mar 2013 12:15 Edited at: 27th Mar 2013 12:16
Hi All

Thanks in Advance!

I have created a MySQL database on my web server.

I have created a PHP script kept in a 'scripts' folder on my web server.

How do I use the AppGameKit http commands to send New High Scores and get existing high scores?

Also, I want to limit the table length to 10 records, how do I check if the players HS should go in?

Sorry for the multiple questions....new to PHP and web stuff!

Where is the digital?
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 27th Mar 2013 15:04
The steps are:
1. Make a connection to the domain:
http = CreateHTTPConnection()
// check for error: http<1
ret = SetHTTPHost(http,"www.domain.com",0)
// make sure good: ret > 0
2. Build your argument string (not the file name, just things like playerid=123 and thescore=5000). Eg. "playerid=123&thescore=5000
Make sure to replace any spaces or characters other than a-z,0-9 with the hex equivalent. A space would be '%20', if you needed the ampersand as part of the argument value, it would be '%26', a forward slash '/' would be '%2F'.
3. Send the page request (I prefer asynchronous because you can do things to show that the process is not hung):
async = SendHTTPRequestAsync(http,"scripts/script.php",argstring)
timeoutat = Timer() + 60.0
4. Wait for the results:
while (GetHTTPResponseReady(http) = 0) and (Timer() < timeoutat)
// show something
endwhile
5. Check results
if Timer > timeoutat
// timeout occurred, do something
else
// get the results
thereturn = GetHTTPResponse(http)
// process the string
endif

In my scripts, I return lots of information by putting together a string with a delimiter ('|'). If I need subinformation, then I use a second one ('~') in the groups between the '|'s.

The same script that accepts the input on your server can check to see if the uploaded score is in the top ten. Get the minimum score stored ("SELECT scoreid,MIN(score) FROM score_table"). If the uploaded score is not greater than it, ignore it. If it is, then update it.

It is a good idea to have an unique id value stored with the scores so that you can simply replace the value ("UPDATE score_table SET score=newscore WHERE scoreid=oldid").

Do you know how to get the values passed up in a script? ($aval = $_REQUEST['varnam']. This assumes a relatively current version of PHP on your server.

Are you familiar with MySQL (and relational databases in general)?

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
The Daddy
15
Years of Service
User Offline
Joined: 13th Jan 2009
Location: Essex
Posted: 27th Mar 2013 16:51
AL

Many many thanks!

Where is the digital?
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 27th Mar 2013 16:57
Always glad to help.

Are you working in Tier 1 or Tier 2?

If you are using Tier 2, I have a class created for doing http stuff (building arguments with proper escaping, extracting return strings and substrings and such). Are you interested?

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master

Login to post a reply

Server time is: 2024-05-07 07:12:36
Your offset time is: 2024-05-07 07:12:36