Saturday, 11 April 2020

Corona SDK – Saving player score on server using PHP

Corona SDK – Saving player score on server using PHP



Corona SDK provides methods of sending data to a server via Lua sockets. It can use GET and POST
just as well, leaving it up to the developer to make the final decision. In addition to sending data,
retrieving the server generated response is convenient when it’s encoded in JSON format.
An example of a GET and POST request looks like this:

local query = "id=1&game=3&score=100"
local query2 = "id=1&game=2&score=100"
local serverUrl = "http://mygame.com/index.php/savescore/"
local getHTTP = serverUrl .. "?" .. query
-- GET request. There is no second body paramater
local body, code, headers = http.request( getHTTP )
-- POST example
local b, c, h = http.request( serverUrl, query2 )
If the server responds with a JSON format, just use json.decode()

No comments:

Post a Comment