- Home /
How do I know if my game is connecting to Kongregate's API?
Hello. I might have gotten my API to connect, but I have no idea. How do I know if I successfully connected? The game is unpublished. Thank you. -Keavon
EDIT: This is my script:
// Begin the API loading process if it is available
Application.ExternalEval(
"if(typeof(kongregateUnitySupport) != 'undefined'){" +
" kongregateUnitySupport.initAPI('MyUnityObject', 'OnKongregateAPILoaded');" +
"};"
);
var isKongregate = false;
var userId = 0;
var username = "Guest";
var gameAuthToken = "";
function OnKongregateAPILoaded(userInfoString){
// We now know we're on Kongregate
isKongregate = true;
// Split the user info up into tokens
var params = userInfoString.Split("|"[0]);
userId = parseInt(params[0]);
username = params[1];
gameAuthToken = params[2];
}
function OnGUI(){
GUI.Box(Rect(0,0,100,20), username);
}
Thank you!
Answer by Borgo · Jan 29, 2011 at 08:12 PM
You can use OnGUI function:
function OnGUI(){ GUI.Box(Rect(0,0,100,20), username);
}
there are a delay about 5 seconds, it will start showing "Guest". After connected, will show the username connected.
Edit:
For your edit: You need to rename your unity object the same name as you call in the function:
kongregateUnitySupport.initAPI('MyUnityObject', 'OnKongregateAPILoaded')
In this line, MyUnityObject is the name of the object with this script.
The ExternEval function is used in Start function;
Thank you. I edited the post to show the script I am currently using. Could you comment or give an other answer to that for use of your answer? Thank you!
I added both of them, but it says I'm a guest on $$anonymous$$ongregate. :( I'm signed in
I had the some problem. $$anonymous$$ake sure your object is named $$anonymous$$yUnityObject
What do you mean by my object? The GameObject the connect + display script is attached to?
I am going to edit the question again with my current script. Then you can add a second answer correcting it, if you don't $$anonymous$$d. It'll sure be a vote up and a best answer!
Answer by Chris 27 · Feb 13, 2011 at 11:16 PM
@Keavon Yes, where it says 'MyUnityObject' replace that with the name in the inspector of your thing that this script is attached to. So, for example, create a Cube in scene view, attach the script to it and in the script it should read kongregateUnitySupport.initAPI('Cube', 'OnKongregateAPILoaded');