Kongregate Tutorial - 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.

Thanks Mitch! This will come in handy.

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

Awesome, thanks. Implementing the Kongregate API is actually a lot simpler than I thought.

I was just looking into kong API myself the other day. This will certainly come in handy.

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.

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.

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.

What about badges?

http://www.kongregate.com/developer_center/docs/statistics-api-tips

Badges are created by the Kongregate staff. I haven’t submitted anything worthy of badges yet but I’d assume you can either email them or they will take a look at your game if it gets popular enough.

Thanks a lot for the help, very much appreciated!

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.

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! =)

Its ok i think i can figure it out just by messing around with your project thx a lot for your share!

Hugs!

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:

using UnityEngine;
using System.Collections;

public class Kongregate : MonoBehaviour
{
	static Kongregate instance;

	void Start()
	{
		if(instance == null){
			Application.ExternalEval("if(typeof(kongregateUnitySupport) != 'undefined'){kongregateUnitySupport.initAPI('" + gameObject.name + "', 'OnKongregateAPILoaded');};");
			instance = this;
		}
	}

	static bool isKongregate = false;
	static uint userId = 0;
	static string username = "Guest";
	static string gameAuthToken = "";

	void OnKongregateAPILoaded(string userInfoString)
	{
		// We now know we're on Kongregate
		isKongregate = true;
		// Split the user info up into tokens
		string[] parameters = new string[3];
		parameters = userInfoString.Split("|"[0]);
		userId = uint.Parse(parameters[0]);
		username = parameters[1];
		gameAuthToken = parameters[2];
	}
	
	public static void SubmitStatistic(string stat, int val)
	{
		if(isKongregate)
		{Application.ExternalCall("kongregate.stats.submit",stat,val);}
	}
}

Thx for you share c# ftw! =)

Thank you very much. it is very helpful.

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! =)

Did you mean via playerprefs or kongregate? No idea about how to do the latter, sorry.

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! =)