i have acount of free webhost…
and i want to connect it into corona to save score and name only…
i dont know how to connect it into corona…
HELP.!
:( <_< -_-
i have acount of free webhost…
and i want to connect it into corona to save score and name only…
i dont know how to connect it into corona…
HELP.!
:( <_< -_-
i use to have code that this. i never completed it, it only saved name and score but there was no login process or unique user names. i’ll see if i can find it
Generally speaking, you’re going to have to setup a database on your host, most likely MySQL to have the necessary tables to track the data you want to save and retrieve. Next you will need to write some server side code in a language like PHP or Python that can communicate with the database and yet still output data to web requests. The scripts that do this would have a URL like:
http://yourhost.com/yourapp/getscore.php
If you created a script called getscore.php that talked to the database. In Corona SDK you then use the network.request() API to get the data, something like:
network.request(“http://yourhost.com/yourapp/getscore.php”, “GET”, callbackListener)
Where callbackListener is a function that handles getting the results of the call back into your app. You would be responsible for managing any security needs for your server and database. Your scripts would need to be hack proof (no SQL injections, no clearly visible passwords, one way encrypted password hashes on the server side.
If you’ve never done this before and don’t have experience with network programming, Corona SDK offers several plugins for doing this, like PlayTogether as well as using Google Play Game Services or Apple’s GameCenter to track leaderboards for high scores. Several people in the community have been putting together an easy to use Parse.com setup if you want more database flexibility. You would need to search the forums for parse to find those threads.
Rob
I recommend the play store api it save your scores to a sever and check it for you. Every easy try it
I recommend the play store api it save your scores to a sever and check it for you. Every easy try it
yes sir… ders no log-in process… it save name and score only…
hope u find it… tnx
i have already created a database in my free webhost… table name ‘player’ 2 fields only ‘name’ and ‘score’.
but i dont know how to connect it corona … i dont havent experience of network programming so i ithink i use plug-ins…
can you give a link sir for tutorials… ?
https://coronalabs.com/blog/2013/06/25/tutorial-introducing-google-play-game-services/ hope this help any questions ask me I am here. Happy coding …
https://play.google.com/store/apps/details?id=com.boxingstudiogames.jetfighter use my game as guide hope this help
I wrote this long before I came to Corona Labs: http://omnigeek.robmiracle.com/2012/04/15/using-corona-sdk-with-rest-api-services/
That should get you started.
Rob
sir Rob? can i access the mysql database of my free webhost into the corona without using php…?
because no need to view the score and the web. its only in the device…
i think ur familiar this…
$mysql_host = “mysql6.000webhost.com”;
$mysql_database = “a9679956_TR1”;
$mysql_user = “a9679956_ian”;
$mysql_password = “juario0123”;
–sir ROB when i access the webserver using this…
network.request( “http://mysite.com/api/login.php?playername=” … mime.b64(username) … “&password=” … mime.b64(password), “GET”, callback )
–then in the php file.
if(isset($_GET)) {
$playername = base64_decode($_GET[“playername”]);
$password = base64_decode($_GET[“password”]);
}
then where is the part to save the the ‘NAME’ of the Player and ‘Score’?
example after the game…
he input the name ‘IAN’ then he’s score is ‘100’…
how can i do that?
when i access into my webserver …
it is nesessary
to have a username and pasword?
network.request( “http://mysite.com/api/login.php?playername=” … mime.b64(username) … “&password=” … mime.b64(password), “GET”, callback )
–then in the php file.
if(isset($_GET)) {
$playername = base64_decode($_GET[“playername”]);
$password = base64_decode($_GET[“password”]);
}
You have asked three questions here. First, you could use the lua.socket library and open the MySQL database directly, but you would have to be very familiar with socket communications and the MySQL packet protocols, which even with my years of experience writing socket code, is not a project I would want to tackle, when a few lines of PHP will bridge the gap. I would recommend using a PHP layer in between, even if you’re only going to have your app access it.
Do you need a username/password? I suppose the technical answer is No, but do you really want anyone calling your script on your server and setting player scores? You don’t need it to get a list of scores. But for any script that writes you want to protect your database from being hacked.
Finally, the blog post was not a complete tutorial on saving scores. It was to show you how you could get started with PHP, MySQL and Corona. It’s up to you to figure out the rest. You should spend time learning how HTTP GET requests work, how parameters are passed as part of the URL.
Rob
sir ROB
i cant insert in my php,
what the problem of this…
–main.lua
local mime = require(“mime”)
local json = require(“json”)
local playername = “dasiglangpls”
local playerscore = “200”
local URL = “http://1dermindstudios.comyr.com/submitscore.php?playername=”…mime.b64(playername)…"&playerscore="…mime.b64(playerscore)
local function loginCallback(event)
if ( event.isError ) then
print( “Network error!”)
else
print ( " success " )
end
return true
end
network.request( URL, “GET”, loginCallback )
–PHP
<?php
define(“DB_DSN”,‘a9679956_TR1’);
define(“DB_HOST”,‘mysql6.000webhost.com’);
define(“DB_USER”,‘a9679956_ian’);
define(“DB_PASS”,‘juario01’);
// Connecting, selecting database
$link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die('Could not connect: ’ . mysql_error());
mysql_select_db(DB_DSN) or die(‘Could not select database’);
if(isset($_GET)) {
$playername = base64_decode($_GET[“playername”]);
$playerscore = base64_decode($_GET[“playerscore”]);
$query = ‘INSERT INTO player (playername,playerscore) VALUES ("’.mysql_real_escape_string($playername).’","’.mysql_real_escape_string($playerscore).’")’;
$dbresult = mysql_query($query, $link);
if (!$dbresult) {
$result = array();
$result[“result”] = 403;
$result[“message”] = mysql_error();
mysql_free_result($dbresult);
exit;
}
sir what is the problem of this?
attemt to index global ‘json’ (a nil value) ?
sir forget na previous question…
this is my last question…
when i used insert statement why null value to store…
this my main.lua
local myNewData
local json = require (“json”)
local decodedDatalocal playerName = “sos”
local playerscore = “200”local function networkListener( event )
if ( event.isError ) then
print( “Network error!”)
else
myNewData = event.response
print ("From server: "…myNewData)
decodedData = (json.decode( myNewData))
– SaveData()
end
end
–endlocal URL = “http://1dermindstudios.comyr.com/submitscore.php?playername=” …(playerName) … “&playerscore=” …(playerscore)
network.request( URL, “GET”, networkListener )
then my php file
<?php
$host=“mysql6.000webhost.com”;
$username=“a9679956_caps2ne”;
$password=“blabla”;
$db_name=“blabla”;$con=mysql_connect("$host", “$username”, “$password”)or die(“cannot connect”);
mysql_select_db("$db_name") or die (“cannot select DB”);mysql_select_db("$db_name") or die (“cannot select DB”);
$sql = “select * from player”; //replace with your table name
$result = mysql_query($sql);
$json = array();
$count=0;
if(mysql_num_rows($result)){
while($row=mysql_fetch_row($result)) {
$count = $count+1;
$json[“movie”.$count]=$row;
}
}
mysql_close($db_name);
echo json_encode($json);
?>
You probably need to add some “echo” statements in your PHP to see what your values are. echo is the same to php as print is to Lua.
Rob
sir where i can put echo?
$con=mysql_connect("$host", “$username”, “$password”)or die(“cannot connect”);
mysql_select_db("$db_name") or die (“cannot select DB”);if(isset($_GET)) {
$playername = ($_GET[“playername”]);
$playerscore = ($_GET[“playerscore”]);
$query = ‘INSERT INTO player (playername,playerscore) VALUES
("’.mysql_real_escape_string($playername).’","’.mysql_real_escape_string($playerscore).’")’;
$result = mysql_query($query);
echo json_encode($json);
}
exit
why i cant insert value with this statement?