Hello for some reason I can't get the username from the Kongregate servers. it used to work in another game i made: www.kongregate.com/games/hannesdelbeke/words-from-space when i try the exact same code in another project it doesn't work so i disable everything except the kong API and rebuild "words from space" it shows a black screen with the username on it now I make a pakage of it, put it in my other project, disable everything, and uplaod it and it still doesn't work I tried more then 10 times with different builds and adjusting the script etc, but none works I don't get why not, since it is the exact same thing sending statistics to the server works fine in both projects and when I debug it with firebug both log in correctly so i have no cluea why it shows up on 1 project and not in the other this is my API code Code (csharp): //#pragma strict var isKongregate : boolean = false; var userId : int = 0; var username = "Guest"; var gameAuthToken : String = ""; var kongregate ; var UsernameObj : GameObject ; public var guiSkin : GUISkin; // Begin the API loading process if it is available Application.ExternalEval ( "if(typeof(kongregateUnitySupport) != 'undefined'){" + " kongregateUnitySupport.initAPI('KongregateAPI', 'OnKongregateAPILoaded');" + "};" ); // Register a sign in handler to let us know if the user signs in to Kongregate. Notice how we are using the // Javascript API along with Application.ExternalEval, and then calling back into our app using SendMessage. // We deliver the new user information as a simple pipe-delimited string, which we can easily parse using String.Split. Application.ExternalEval( "kongregate.services.addEventListener('login', function(){" + " var services = kongregate.services;" + " var params=[services.getUserId(), services.getUsername(), services.getGameAuthToken()].join('|');" + " kongregateUnitySupport.getUnityObject().SendMessage('MyUnityObject', 'OnKongregateUserSignedIn', params);" + "});" ); function Awake () { DontDestroyOnLoad (transform.gameObject); username = "Guest"; } /* function Start () { } */ function OnGUI() { GUI.skin = guiSkin; if(username) GUI.Label (new Rect (10,130,300,40), ""+ username); if( isKongregate) GUI.Label (new Rect (10,170,150,40), "connection established"); } function Update () { /*if(username == "hannesdelbeke"){ Camera.main.GetComponent(CubeControl).createLevel = true; }*/ if(UsernameObj) UsernameObj.GetComponent(TextMesh).text = username ; } /* function LoadAPI () { }*/ function OnKongregateAPILoaded(userInfoString){ // We now know we're on Kongregate print("UNITY function loaded"); Debug.Log("ON KONG"); isKongregate = true; // Split the user info up into tokens var params = userInfoString.Split("|"[0]); userId = parseInt(params[0]); username = params[1]; gameAuthToken = params[2]; } // Called when the Kongregate user signs in, parse the tokenized user-info string that we // generate below using Javascript. function OnKongregateUserSignedIn(userInfoString){ var params = userInfoString.Split("|"[0]); userId = parseInt(params[0]); username = params[1]; gameAuthToken = params[2]; } function SubmitScoreLvl(myScore : int , lvl : int) { // Begin the API loading process if it is available Application.ExternalCall("kongregate.stats.submit","ScoreLvl"+lvl,myScore); Debug.Log("score of " +myScore + " submitted"); } function SubmitUnlockLvl(_unlockedLevel : int){ Application.ExternalCall("kongregate.stats.submit","Unlocked",_unlockedLevel); } function SubmitCompleteLvl(_completedLevel : int){ Application.ExternalCall("kongregate.stats.submit","Completed",_completedLevel); } /* // Assuming we have a TextField named "my_txt": function scoresCallback ( result:Object ):void { my_txt.appendText("High score result, success=" + result.success ); for ( var i:int = 0; i < result.list.length; i++ ){ var position:int = i + 1; my_txt.appendText("\n"+position + ". " + result.list[i].username + " - " + result.list[i].score ); } } // Request the list kongregate.scores.requestList ( scoresCallback ); */
Ok I found it but I don't understand why it works in all my other projects I assume something to do with the order Unity runs his scripts maybe so i placed the 2 Application.ExternalEval in the awake and that solved it
Hi Dhajku I have a silly question : could you tell me did you complete converting the "score Callback" function to unity? I have a huge problem on it.