Unity Kongregate API Problem

Hi, I need some help.

I'm having problem implementing the Kongregate API.

I have Used this little script:

var isKongregate = false;
var userId = 0;
var username = "Guest";
var gameAuthToken = "";

function OnKongregateAPILoaded(userInfoString : String){
  // 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 Awake(){
        // Begin the API loading process if it is available
        Application.ExternalEval(
            "if(typeof(kongregateUnitySupport) != 'undefined'){" +
            " kongregateUnitySupport.initAPI('MyUnityObject', 'OnKongregateAPILoaded');" +
            "};"
        );

}

function OnGUI(){
    GUI.Box(Rect(0,0,100,20),isKongregate.ToString());
}

  • I upload the .unity3d to kongregate
  • If I use a externalEval with "alert(typeof(kongregateUnitySupport))", it will alert "Object". It means that the object exists.
  • The Script calls the initAPI function of this script but doesn't call back the OnKongregateAPILoaded function.
  • The GUI.Box ever show the message "False" what is to be modified when the function is called.

I have used this example: http://answers.unity3d.com/questions/33227/how-do-i-implement-the-kongregate-api But doesn't works.

The Kongregate.Package in the Unity.com page have the some problem to me.

please, help me.

Thanks, William Borgo

Is the name of the object the script is attached to 'MyUnityObject'? If not, the callback to OnKongregateAPILoaded will fail.

Another possibility: if you're doing other ExternalEvals that happen to result in javascript errors, subsequent ExternalEval calls will not work.

This looks like a problem with Kongregate Scripts, however they have some games that are able to connect with API.

I sugest you to contact Kongregate support. Maybe they can help you.

If you didn't solve it yet, the following fix worked for me (yippeee) after nothing else did!

http://www.kongregate.com/forums/4-programming/topics/140914-unity-kongregate-api-package-not-connecting?page=1#posts-3126582

Enjoy!