Okay, I manage to get the highscore appear in kongregate , you can see it yourself at
http://www.kongregate.com/games/fundurian/idle-zombie-spitter
Okay, because the unity is very confusing with tons of object and tons of script, I put all the below code inside my main engine java script
lets start
Step1: Open your main engine java script (my case is shoot.js)
Step2: create 4 variable
var KONGREGATE_LOADED: boolean = false;
var USER_ID: int =0;
var USER_NAME: String="Guest";
var GAME_AUTH_TOKEN: String = "";
Step3: under the function start(), call the kongregate webserver for the kongregate unity support
function Start()
{
Application.ExternalEval("if(typeof(kongregateUnitySupport) != 'undefined'){" +" kongregateUnitySupport.initAPI('" + gameObject.name + "','OnKongregateAPILoaded');" + "};");
}
Step4: create this 3 function
function OnKongregateAPILoaded( userInfo:String)
{
KONGREGATE_LOADED= true;
var userStats = userInfo.Split("|"[0]);
USER_ID = int.Parse(userStats[0]);
USER_NAME = userStats[1];
GAME_AUTH_TOKEN = userStats[2];
}
function APILoaded() : boolean
{
if((USER_NAME != "Guest") && (KONGREGATE_LOADED==true))
{
return true;
}
else
{
return false;
}
}
function SubmitData(dataname: String , datavalue: int)
{
if(APILoaded()==true)
{
Application.ExternalCall("kongregate.stats.submit",dataname,datavalue);
}
}
Step5: submit the score, you can put it anywhere, example when you win the game or lose the game,
do note konscore is a variable you can use anyname, when your user score 1000 example you just store it into konscore and call this function to submit to kongregate
SubmitData("HighScore",konscore);
Step6: Open kongregate, under my games -> edit games -> upload new version
- Under statistic API -> click add statistic
- statistic name : HighScore (SUPER SUPER IMPORTANT, MUST MATCH the dataname on top)
- choose max type
- display on leaderboard (tick)
Step7: Now try to play your games, and submit score, wait maybe 5 or 10 minute for it to appear, please be patient
there you go, enjoy, any question feel free to ask
No comments:
Post a Comment