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 / Adding online high score tables for my game.

Author
Message
aviles22
10
Years of Service
User Offline
Joined: 1st Dec 2013
Location: New Jersey, USA
Posted: 21st Mar 2014 19:17
Are there any tutorials or links anybody knows of to do this with AppGameKit for my game?
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 21st Mar 2014 20:26
I think the common way to do it is using the HTTP commands to communicate with a webserver. And then use something on that server like PHP and a MySQL database. With that you can use something like one.com or any other web hotel to host your server.

aviles22
10
Years of Service
User Offline
Joined: 1st Dec 2013
Location: New Jersey, USA
Posted: 21st Mar 2014 21:32
I already have a host server where I can put my SQL database to hold high scores. That totally answers part of the question. I have to read about the HTTP commands. Do they let you communicate with a database or is it possible to setup a connection and dataset to an SQL database through AppGameKit BASIC TIER1? If this is possible then wow AppGameKit is limitless!
aviles22
10
Years of Service
User Offline
Joined: 1st Dec 2013
Location: New Jersey, USA
Posted: 21st Mar 2014 22:18
OK. Just checked out the HTTP commands and I highly doubt if I can connect and communicate with an SQL database from within AppGameKit Tier 1 which led me to this idea:

Create a text file on my host website which will hold the top 5
scores for anyone playing my game: highscores.txt

highscores.txt file contents example:
Joe,Gina,Bill,Tony,Jill::1000,785,655,580,450

Now in my AppGameKit Game:

To view current high scores player will click on a "Leader Board" button which will be coded to download the highscores.txt file and
display them on screen.

To write a high score to highscores.txt on my server when the game is over or player exits game I'm thinking of creating a function that will download the highscores.txt file and if the players current score is greater than any of the top 5 current scores then rewrite the new highscores.txt file to my server.

Is this crazy? Or am I on the right track. Of course I don't know if there will be errors or consistency if multiple players are trying to open or write to the same file at equivalent times.
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 21st Mar 2014 22:42
I think that is fine for testing but as you say, it could cause problems. If you create a PHP script that goes between the game and the database, you should be safe.

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 22nd Mar 2014 04:06
There is no direct communications with a database server. You need to do everything through http calls to a page that handles your input and sends stuff back.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 22nd Mar 2014 10:53
I'm hoping this question may be answered for you in the next newsletter, just hold on another week

Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 22nd Mar 2014 15:59
I'll do an article on this for Tier 1 and PHP for the next newsletter.

aviles22
10
Years of Service
User Offline
Joined: 1st Dec 2013
Location: New Jersey, USA
Posted: 22nd Mar 2014 19:06
Will be very appreciated and helpful to many. Thanks in advance!
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 23rd Mar 2014 00:15
aviles22, to answer your question in short - I would not recommend tying the online score system to a single file. Reason being that player A might have a score of 215 which the server thinks is the high score. Player B has a score of 315 which the server will also think is a high score. Say that player A has a very spotty internet connection so it takes longer for him to upload the file back to the server than it takes player B. Player B's score would never get on the list. A database is best. That way you can just blindly insert rows and then later do a query on the top 10 and leave all the other scores in there until at some later date you decide to clean it up... if you care to at all.

aviles22
10
Years of Service
User Offline
Joined: 1st Dec 2013
Location: New Jersey, USA
Posted: 23rd Mar 2014 14:47 Edited at: 23rd Mar 2014 14:53
Yes, I understand and I have a very extensive background with database programming. And going further with the future of my AppGameKit experience, with only using AppGameKit for about a month and a half I already completed a pretty decent game (in my opinion) which people are already addicted to. The power of AppGameKit is quite amazing and I am very positive that I can use AppGameKit for alot more than just gaming APPS. I have some ideas on how to bring my SQL database into AppGameKit but don't know where to start.

I can program in C++ but I truly enjoy TIER1 AGK. Much less time involved as for now this is my hobby as I run my own HVAC Company.
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 23rd Mar 2014 15:59
You should really add PHP to your skillset. It is much safer to connect to a PHP script than directly to the database. PHP is used to code most modern forums and websites. It is very powerful and easy-to-use, you can code very advanced servers and run them on almost any website.

Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 23rd Mar 2014 16:12
Yup. PHP is what you need here. I'll give some quick examples in the next newsletter

=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 24th Mar 2014 12:30
I am very much looking forwards to the next newsletter then, lol; the PHP side of online hi score boards has always eluded me.

Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 24th Mar 2014 15:06 Edited at: 24th Mar 2014 15:07
My advice, grab a book on PHP. They all (I think) teach you how to setup an Apache server with MySQL, and there's some easy options out there that I can't remember at the moment. It's all very easy to learn. If you can code AppGameKit tier 1 then no problems with PHP. You just have to get used to ; at the end of every line and == instead of = in IF statements. And it's case sensitive on variable names which can be annoying at times. It's way easier than C++. SQL calls can be a bit tricky to get right at first but they are very simple.

aviles22
10
Years of Service
User Offline
Joined: 1st Dec 2013
Location: New Jersey, USA
Posted: 24th Mar 2014 19:58 Edited at: 24th Mar 2014 21:46
As I wait for the next newsletter I have anxiously studied the AppGameKit Online High Score Toolkit found on these forums.

I had some trouble connecting and organizing folders on my GoDaddy hosting account but I have successfully managed to get the example AppGameKit Online High Score Toolkit work. Very, Very Awesome.

Going to study the source code some more!

AGK is LIMITLESS! I Love It Even MORE NOW!
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 26th Mar 2014 16:51
Looking forward to the info's in the newsletter on this - something I think a lot of people will appreciate it... theres a lot I want to be doing with AppGameKit that relies on server side stuff, should be a very interesting read

I am the one who knocks...
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 26th Mar 2014 16:59
The pressure!
I'll do my best. I only started learning PHP about a year ago. I've tried to read books on it but it made me fall asleep. W3Schools.com was the best quick reference for it. There's also the PHP manual online which is awesome because folks give tons of examples. I also had a ton of help from Ancient Lady who was nice enough to look at some of my scripts and tell me how to optimize them

The online high score tutorial is pretty simple. PHP is a really nice language and you can use it either as a procedural language or an object oriented language. I love procedural so the tutorial will be procedural code. Plus I feel that is easiest to teach others with.

SageTech
19
Years of Service
User Offline
Joined: 3rd Dec 2004
Location: Orlando, Florida
Posted: 26th Mar 2014 23:09 Edited at: 26th Mar 2014 23:22
This task is a perfect example of why I think learning a little php is a must for anyone that does programming. Alot of Ruby on Rails zealots tend to hate on us php folks, but the fact is php is easy to learn and quick to see results.

@Naphier
You may want to steer clear of W3Schools, they teach some REALLY bad habits to impressionable php-novices. See: http://www.w3fools.com/

I also understand the allure of purely procedural code, I started with BASIC so OOP concepts were something that escaped me for years, however once you start to use OO in php it really makes for solid, maintainable projects. I also would suggest looking into frameworks, right now I'm particurily fond of laravel, which is something of a rising star in the php community.

Here's a quick and dirty example of a high score submission and retrieval system using the laravel framework. It's almost maddening how simple it makes things:



In this example you would submit a new high score by sending PersonName and PersonScore POST values to yourserver.com/highscores.

To read the top 10 scores, you simply request the page yourserver.com/highscores.

There's really not that much more to it, you just define your connection to a mysql database with a table called high scores and two columns within it called name and score. Its easy of use is like AppGameKit, but for php. It's changed how I develop web apps, and its drastically reduced time to deliver finished products to clients.
aviles22
10
Years of Service
User Offline
Joined: 1st Dec 2013
Location: New Jersey, USA
Posted: 27th Mar 2014 21:59
Naphier and all else who helped, Thank You for your help as I have a nice working Leader Board as far as sending new high scores and also retrieving them from and to MySQL database using PHP scripts with AppGameKit HTML commands. (Works very very fast and accurate!)

The only problem I'm having is multiple instances of a single user being on the leader board. I know how to fix it but don't know how to retrieve the auto ID field when inserting a new record.

When inserting a new user into my database. How can I retrieve the ID field that is set to autonumber in the same script which I'm using to insert the new user?

I need to save the ID into a text file so that it won't duplicate this user when checking future leader board status.
Hockeykid
DBPro Tool Maker
17
Years of Service
User Offline
Joined: 26th Sep 2007
Location:
Posted: 27th Mar 2014 22:04 Edited at: 27th Mar 2014 22:04
After you execute the query, using



Should return the last inserted ID.


Sean

aviles22
10
Years of Service
User Offline
Joined: 1st Dec 2013
Location: New Jersey, USA
Posted: 28th Mar 2014 15:53
$sql="SELECT * FROM $tbl_name WHERE ";

Can someone finish the above query for me?

I've used:
$sql="SELECT * FROM $tbl_name WHERE name LIKE '%T' ";

I just don't think I have the correct characters. I did Google this but single quotes don't work in my PHP Code
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 28th Mar 2014 16:18
$sql="SELECT * FROM $tbl_name WHERE name LIKE '%T' ";
Will return name from $tbl_name where the name ends in T

If you want the name to contain T then you'd use %T%
I suspect you want a more accurate match though and I'd suggest
$nameToFind = strtolower($nameInput);
$sql="SELECT * FROM $tbl_name WHERE LCASE(name)= '".$nameToFind."' ";

Single quote vs. double quote usage is a bit confusing.
In PHP single quotes mean literally what is in them.
Double quotes will allow you to have variables inside of the quotes.
If you're using single quotes for a SQL query in PHP and you need single quotes inside of them (for something like string comparison) then you need to escape the single quotes with a backslash \
Also if you're only looking for one name in the table then put LIMIT 1 on the end of your query so that the query stops as soon as it finds the first one.

@SageTech - w3schools is a good starting point. All w3fools says is the w3schools is slow to update content. They're a very nice quick reference and any source for programming reference can be quickly outdated. I'm not saying all of their stuff is 100% safe or that it even covers the majority that you need to know. It is however a good starting point for people to learn. The better reference by far is PHP.net but most of the language and examples are complicated for beginners.

aviles22
10
Years of Service
User Offline
Joined: 1st Dec 2013
Location: New Jersey, USA
Posted: 28th Mar 2014 16:29
I JUST TRIED:

$nameToFind = "JOHN DOE";
$sql="SELECT * FROM $tbl_name WHERE name = '".$nameToFind."' ";
$result=mysql_query($sql);

AND DIDN'T WORK! I'M STUCK

I know its just a simple mistake!
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 28th Mar 2014 16:38
What error do you get?
What happens if you make the whole query literal like this
$sql = "SELECT * FROM your_actual_table_name WHERE name = 'JOHN DOE'";
If that doesn't work does this work?
$sql = "SELECT * FROM your_actual_table_name WHERE name = '%JOHN%'";
If that doesn't work then does this work?
$sql = "SELECT * FROM your_actual_table_name WHERE 1";
If that doesn't work then does the user have rights to SELECT from the database?

Another note, you might want to use mysqli_query($connection , $sql)
And use mysqli commands as the mysql commands are being depreciated.

aviles22
10
Years of Service
User Offline
Joined: 1st Dec 2013
Location: New Jersey, USA
Posted: 28th Mar 2014 17:15
NAPHIER THANKS AGAIN:

My PHP code below works well. The problem was that I was actually trying to get how many rows existed in the query. For some reason when there is only 1 record found their is an error. I added 2 duplicate records as JOHN DOE and it worked.

So my question is how can I make this work when only one record is found in the query?

I'm not an SQL noob. However, I am a PHP noob!

<?php
header('Access-Control-Allow-Origin: *');
include 'config.php';
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name WHERE name = 'JOHN DOE'";
$result=mysql_query($sql);

$num_rows = mysql_num_rows($result);

while($rows=mysql_fetch_array($result)){ echo $num_rows . chr(10); } mysql_close();

?>
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 28th Mar 2014 17:33
That doesn't make much sense...
Where was the error happening? And what was it saying?
At mysql_num_rows or mysql_fetch_array?

You should also be checking to see that your $result is valid with a
if(!result) {Die('bad query');}

Also you might want to consider a different query to get the count.
"SELECT COUNT(*) FROM $tbl_name WHERE name ='JOHN DOE'"

Again I'd also suggest looking into how to do this with mysqli statements. I've found them easier to use and more reliable.

aviles22
10
Years of Service
User Offline
Joined: 1st Dec 2013
Location: New Jersey, USA
Posted: 28th Mar 2014 18:56
Basically what I'm trying to do is when a user enters there username for the first time on the leader board i want to test the database to make sure that username doesn't exist.

if doesn't exist:
returning a null username or a recordnumber of 0

if it does exist:
returning a username with text or a recordnumber of 1
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 28th Mar 2014 19:20 Edited at: 28th Mar 2014 19:26
If you make the username column in your table unique, then the INSERT would fail.

Oh, and ditch the procedural mysql commands, they're obsolete now. Use mysqli for a better object oriented approach. And this is a good example site.



Login to post a reply

Server time is: 2024-11-25 03:27:40
Your offset time is: 2024-11-25 03:27:40