In this blog post, we will take you through a quick start Corona game sample which uses leaderboard APIs to get you started with App42 backend APIs.
Following are the steps to get started with it:
- Register with App42 platform.
- Create your App once you are on Quick Start page, and get your API Key and Secret Key
- If you are already registered, login to AppHQ console and get your API Key and Secret Key from App Manager –>Application Keys section.
- Create a new game in AppHQ console by clicking Add Game button in the Game panel (AppHQ Left Menu/Business Service Manager/Game Service/Game).
- Download the SDK & sample from our Git repo.
- Unzip the downloaded file on your system.
- Initialize App42 SDK by putting the APIKey & SecretKey in Constant.lua file (sample/App42-LeaderBoard-Sample/Constant.lua) and add your game name which you have created in the above steps and Constant file contains all the constants used in sample (e.g. username, email, password, game name etc.). Edit the variables as per your requirements.
- Save your project and run.
Design Details
Below are the API calls from App42 Corona SDK that has been used for social engagement and user management feature in this sample:
Initialize App42 Corona SDK
App42API:initialize("","")
local scoreBoardService = App42API:buildScoreBoardService()
local userService = App42API:buildUserService()
local gameName = "" -- Created in Step #4
local App42ScoreBoardCallBack = {}
local App42UserCallBack = {}
Saving user score on the cloud :-
local userName = "Nick" -- Name of the user for which you want to save score.
local gameName = "" -- Created in Step #4
local gameScore = 1000
scoreBoardService:saveUserScore(gameName,userName,gameScore, App42ScoreBoardCallBack);
function App42ScoreBoardCallBack:onSuccess(object)
print("Game name is "..object:getName())
print("userName is : "..game:getScoreList():getUserName())
print("score is : "..game:getScoreList():getValue())
print("scoreId is : "..game:getScoreList():getScoreId())
end
function App42ScoreBoardCallBack:onException(object)
print("Message is : "..object:getMessage())
print("App Error Code is : "..object:getAppErrorCode())
print("Http Error Code is : "..object:getHttpErrorCode())
print("Error Detail is : "..object:getDetails())
end
User Authentication :-
local userName = "Nick"
local password = "**********"
userService:authenticate(userName,password,App42UserCallBack)
function App42UserCallBack:onSuccess(object)
print("User Name is : "..object:getUserName())
print("Session Id is : "..object:getSessionId())
end
function App42UserCallBack:onException(object)
print("Message is : "..object:getMessage())
print("App Error Code is : "..object:getAppErrorCode())
print("Http Error Code is : "..object:getHttpErrorCode())
print("Error Detail is : "..object:getDetails())
end
Visit our App42 documentation page to learn more. Please share your feedback with us at support@shephertz.com
.
Leave A Reply