Search Unity

Kongregate Tutorial - Carpal Clicker

Discussion in 'Made With Unity' started by Fenrisul, Feb 7, 2011.

  1. Fenrisul

    Fenrisul

    Joined:
    Jan 2, 2010
    Posts:
    618
    http://www.kongregate.com/games/Fenrisul/carpal-clicker

    For those of you interested or having trouble with Kongregate API integration with Unity - I've put together the most simplistic and complete game I could as a back-end test for my own project (soon to show up as well).

    Carpal Clicker + Kongregate API integration examples unity project source
    http://www.xdtech.net/unity/CarpalClicker.zip

    Project contains examples of user identification, score submission, and achievement submission (tracked locally and submitted as a standard kongregate statistic)


    Moderators:
    I can't seem to upload that zip as an attachment; is there a rule/issue that I'm missing? Its ~4mb.
     
    Last edited: Feb 7, 2011
  2. Blacklight

    Blacklight

    Joined:
    Dec 6, 2009
    Posts:
    1,241
    Thanks Mitch! This will come in handy.
     
  3. starpaq

    starpaq

    Joined:
    Jan 17, 2011
    Posts:
    118
    Yes thanks very much. I haven't found time to go through it in detail. I just know that at first glance it seemed kind of daunting to figure out the api. Hopefully this will help out.

    thanks again
     
  4. TheLastBanana1

    TheLastBanana1

    Joined:
    Jan 20, 2011
    Posts:
    13
    Awesome, thanks. Implementing the Kongregate API is actually a lot simpler than I thought.
     
  5. bgivenb

    bgivenb

    Joined:
    Sep 15, 2010
    Posts:
    449
    I was just looking into kong API myself the other day. This will certainly come in handy.
     
  6. Iron-Warrior

    Iron-Warrior

    Joined:
    Nov 3, 2009
    Posts:
    838
    This is really great! I spent a day about a week ago working to figure out the KongAPI, but it can be a little daunting though at first. Having something like this would really have made it easier.

    Just about to release my game onto the site, but I can't seem to figure out how to test stats in the preview mode...I have a debugger showing that I am connected to the API, but I don't quite get how the stats and leaderboards work.
     
  7. Fenrisul

    Fenrisul

    Joined:
    Jan 2, 2010
    Posts:
    618
    if you've added statistics via the game setup page then the leaderboards will just simply work (even in preview mode)

    If you don't see them showing up, theres a few things I've noticed.

    Until your game has been "Viewed" 10 times leaderboards tend not to show up. Sometimes it just takes an hour or two as well before they start appearing in the Highscores tab next to your game. Play thru a bit and do what you can to ensure that you're actually sending data. You can get that "10 views" by refreshing the page a few times.
     
  8. Iron-Warrior

    Iron-Warrior

    Joined:
    Nov 3, 2009
    Posts:
    838
    Yeah, I eventually fiddled around with the stat updates, refreshed it a bunch and it seems to work. Sometimes it feels like it takes a minute to update the leaderboards though.
     
  9. Persona

    Persona

    Joined:
    Jul 25, 2010
    Posts:
    280
    What about badges?
     
  10. Fenrisul

    Fenrisul

    Joined:
    Jan 2, 2010
    Posts:
    618
    Last edited: Feb 11, 2011
  11. Zombie Gecko

    Zombie Gecko

    Joined:
    Nov 25, 2010
    Posts:
    32
    Thanks a lot for the help, very much appreciated!
     
  12. CodeCody

    CodeCody

    Joined:
    Apr 27, 2010
    Posts:
    440
    Sweet a kong api tut. Hay I have bin wondering, do unity games get the extra 10% from adding the api?
    Because I have had the api working for awhile now (well I can submit stats anyway) and I am still not getting it.
     
  13. Vinícius Sanctus

    Vinícius Sanctus

    Joined:
    Dec 14, 2009
    Posts:
    282
    This is awesome friend i just dumbly tried to talk to you trought Kongregate just now.

    The thing is, can you help me with using the Kongregate's API like a game DB like almost every flash game does?

    I really need to store some RGB values, Armor/Weapon types and all kind of stuff for my character creator.

    But for what i´ve seen all, all statistics seems to be public.

    Please help!

    Hugx and thx! =)
     
    Last edited: Mar 30, 2011
  14. Vinícius Sanctus

    Vinícius Sanctus

    Joined:
    Dec 14, 2009
    Posts:
    282
    Its ok i think i can figure it out just by messing around with your project thx a lot for your share!

    Hugs!
     
  15. DarthBenedict

    DarthBenedict

    Joined:
    Dec 7, 2010
    Posts:
    26
    Pretty handy, though I had to translate kongregate.js to c# to get it to work with my game.

    Try it out here - play last stand to try for a high score

    And here's the c# version:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class Kongregate : MonoBehaviour
    6. {
    7.     static Kongregate instance;
    8.  
    9.     void Start()
    10.     {
    11.         if(instance == null){
    12.             Application.ExternalEval("if(typeof(kongregateUnitySupport) != 'undefined'){kongregateUnitySupport.initAPI('" + gameObject.name + "', 'OnKongregateAPILoaded');};");
    13.             instance = this;
    14.         }
    15.     }
    16.  
    17.     static bool isKongregate = false;
    18.     static uint userId = 0;
    19.     static string username = "Guest";
    20.     static string gameAuthToken = "";
    21.  
    22.     void OnKongregateAPILoaded(string userInfoString)
    23.     {
    24.         // We now know we're on Kongregate
    25.         isKongregate = true;
    26.         // Split the user info up into tokens
    27.         string[] parameters = new string[3];
    28.         parameters = userInfoString.Split("|"[0]);
    29.         userId = uint.Parse(parameters[0]);
    30.         username = parameters[1];
    31.         gameAuthToken = parameters[2];
    32.     }
    33.    
    34.     public static void SubmitStatistic(string stat, int val)
    35.     {
    36.         if(isKongregate)
    37.         {Application.ExternalCall("kongregate.stats.submit",stat,val);}
    38.     }
    39. }
    40.  
     
    Last edited: Apr 4, 2011
  16. Vinícius Sanctus

    Vinícius Sanctus

    Joined:
    Dec 14, 2009
    Posts:
    282
    Thx for you share c# ftw! =)
     
  17. cemC

    cemC

    Joined:
    Dec 23, 2010
    Posts:
    214
    Thank you very much. it is very helpful.
     
  18. Vinícius Sanctus

    Vinícius Sanctus

    Joined:
    Dec 14, 2009
    Posts:
    282
    I see you have used PlayerPrefs. Does anyone know how can one retreive instead of just submitting a statistic value from the API? Thx a lot hugs! =)
     
    Last edited: Apr 8, 2011
  19. DarthBenedict

    DarthBenedict

    Joined:
    Dec 7, 2010
    Posts:
    26
    Did you mean via playerprefs or kongregate? No idea about how to do the latter, sorry.
     
  20. Vinícius Sanctus

    Vinícius Sanctus

    Joined:
    Dec 14, 2009
    Posts:
    282
    I meant using Kongregate´s statistic system as a remote data base.

    For instance you store game configurations as int type on a player hidden statistic and retreive it everytime the player log in.

    So you can make player ingame data persistent no matter where he´s logging from.

    Using Unity´s PlayerPrefs make it local, in order words, make it way worse.

    Thx for your fast reply friend!

    Hugs! =)
     
  21. Vinícius Sanctus

    Vinícius Sanctus

    Joined:
    Dec 14, 2009
    Posts:
    282
    Just found out that it is not possible. My only hope now is the Shared Content feature within Kong's API. But really not sure if that´s also possible trought unity. =(
     
  22. DarthBenedict

    DarthBenedict

    Joined:
    Dec 7, 2010
    Posts:
    26
    If you don't mind setting up some kind of database of your own, you can do it through that and then link kongregate to that for the publicly displayed stats. That'd probably be better than limiting your games to kongregate as well, though it does have the obvious disadvantage of having to get your own DB.
     
  23. Vinícius Sanctus

    Vinícius Sanctus

    Joined:
    Dec 14, 2009
    Posts:
    282
    Setting my own DB is not really the problem, but hosting my own DB 24/7, that´s a bitch.

    Unfortunatelly im going for PlayerPrefs FTL. So everything will be stored locally =(


    Hugs! =)
     
  24. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,822