[Kongregate API] High Scores (locked)

192 posts

Flag Post

Note: The following information is out of date. Please refer to our new API Documentation here: http://www.kongregate.com/pages/kongregate_api

This method is now deprecated. Please use the Statistics/Challenges version of the API for AS2.

This is a simple guide on how to integrate our high scores API into a flash game. Unfortunately, we do not yet support Shockwave games.

OVERVIEW

The Kongregate High Scores API allows you to submit scores, as well as retrieve the top scores for your game. Scores reported by the statistics API will also show up in the high scores list. High scores will be visible in many places on Kongregate automatically, such as the game page and in chat, so your game does not necessarily have to display high scores, reporting them is the most important part. The high scores API is meant to provide a simple interface for submitting and retrieving high scores, without having to set up statistics on the server beforehand.


IMPLEMENTATION

First, you will need to add a line of code that will cause your game to connect to our servers. It should be placed as early in the timeline as possible, usually on the first frame. You may copy and paste this code into your FLA or ActionScript:


_root.kongregateServices.connect();


After that, you can start submitting scores! The submit function takes a single argument, which is the score you wish to submit for the player. It is recommended that you submit this score at the end of the game, but you can submit whenever you like.

_root.kongregateScores.submit(1000); // The user got a score of 1000


In order to get the high score list from the server, you can use the requestList method, which takes 2 arguments. The first is a callback function that will be called when the request has been processed by the server. The second is an optional object to bind to the callback as the this pointer. It is fairly typical to simply pass this in, if necessary.

var scoresCallback:Function = function( result:Object ){
	trace("High score result, success=" + result.success );

	for( var i:Number = 0; i < result.list.length; i++ ){
	    var position:Number = i + 1;
	    trace( position + ". " + result.list[i].username + " - " + result.list[i].score );
	}
}
_root.kongregateScores.requestList( scoresCallback, this );

As you can see the object passed into the callback function has several fields: success will be either true or false depending on if the request was successful, and list is an array of the high scores. Each element in the array has a username and a score.


HIGH SCORE MODES

If your game has different modes or categories for which to submit high scores, you can use the setMode function. This function takes a single argument, which is the name of the mode you wish to switch to. You should call setMode with your default mode right after the call to kongregateServices.connect(). If you do not wish to support multiple modes, this call is not necessary, and can be ignored. When setMode is used, it sets the mode for both submits and high score list retrievals. setMode should typically be called when the player selects the game mode or difficulty, as it is also used to determine which high score list is displayed by default in chat.

_root.kongregateServices.connect();
_root.kongregateScores.setMode("Normal");
_root.kongregateScores.submit(1000); // Will submit a score of 1000 for normal mode
_root.kongregateScores.setMode("Hard");
_root.kongregateScores.submit(500); // Will submit a score of 500 for hard mode

FEEDBACK

Feel free to post any questions in this thread.

 
Flag Post

after connecting, how do you close the connection? or is that not neceessary?

Also, err, what’s the point of having traces in your code when you’re still going to have to upload your game before being to work with the api? Perhaps if you put in “showDebug” instead? That way people know how to use the chat window as a debugger.

Thanks for the API :)
(now hurry up with AS3 api! – whips – )

 
Flag Post

Yeah, the trace was just an example to show the data format, it has no real use as shown. You do not need to worry about disconnecting. Just so you know, I want to get AS3 going just as badly as you do, but unfortunately there are other priorities ahead of it :[

 
Flag Post

tis cool. :)

 
Flag Post

Awesome work. Just get the AS3 version out, and the multiplayer API. licks lips

 
Flag Post

I’ve just been trying to implement this onto my newer game Atom Juggler, but when it gets to the send score frame, nothing happens :(.

Here’s the code I used:



_root.kongregateScores.setMode(“High Scores”);
_root.kongregateScores.submit(ttl);
_root.kongregateScores.setMode(“High Combos”);
_root.kongregateScores.submit(ncmb);
var scoresCallback:Function = function (result:Object) {
for (var i:Number = 0; i<result.list.length; i++) {
var position:Number = i+1;
}
};
_root.kongregateScores.requestList(scoresCallback,this);



Thanks in advance if you can help.

 
Flag Post

Thanks for this info! I have a question though; I am making a shooter and I have both a high-score and a high-level that I wish to submit. I can see that I can use the setMode and submit the score in one mode and the level in another, which is good, but ideally I also want people to be able to see what level that high score was achieved with, and similarly, what score the high level was achieved with. Basically, the two statistics are tied together. Also, if I submit using the highscore api, do i also submit with the statistics api?

Btw, the preloader is incomplete. It is missing some font, and does not contain any animation.

 
Flag Post

I uppload my game (Color Buster) with a bug correction, and the score api resets… Its normal? Because I need to upload another correction, and will reset the scores again?

 
Flag Post

Mepixa: Your scores should not be resetting when you upload a new version of your game. I will definitely look into this issue.

Salman: The high scores API is mostly just a simplified version of the statistics API. You can use whichever one you are more comfortable with. For your problem, it sounds like you would want to use something like “LevelX” as the mode, where X is the level, so that the high scores dropdown would contain “Level1”, “Level2” etc. This should work depending on how many levels you have. If you have too many levels, it might start to become annoying for players to view high scores.

 
Flag Post

The high score API is brilliant! I don’t think it could be an simpler then this to do a high score.

Really two lines of code… if you have a score in your game their is no reason not to use this!

:)
Adam

 
Flag Post

I’m just working on my first game for k and I’m trying to figure out how to secure the high scores. It’s great the API is so stright-forward but I think the hackers are going to be able to decompile and cause problems with the high score tables way too easily. Thoughts?

 
Flag Post

Nate, Kongregates high score system works a little differently than typical setups. BenV can give you the details but I wouldnt worry too much about it; the services have been set up so that worry rests on Kongregate. Just dont store your scores in a flash shared object unless you encypt the data.

 
Flag Post

Thats for us to worry about, not you! However, feel free to read 2DArray’s topic about memory hacking, which you can prevent!

 
Flag Post

I’m having trouble getting this API implemented. I believe I am connecting to the API just fine, however all of values in the list array are “undefined”, even after I have submitted (I assume with success) my scores while testing the game. Note: I have not published my game, just uploaded and testing at this point. Does the game need to be published for this to work?

Thanks!

 
Flag Post

Hey, I can’t seem to find your game, did you submit it from a different username? I also tried to find high scores submitted by the user “MercilessGames” and couldn’t find any. If you could give me a link to the preview version of your game I could look into this further.

 
Flag Post

BenV theres a bug with your code.

I’m not a programmer but I noticed the errors logging unto my screen when i played a few games.

For some reason unbenownst to myself the code cant calculate the upper boundaries of my amazingness…. Well I guess it could just be the limitations of todays computers.. sigh

 
Flag Post

tony28 could you clarify this, or maybe post a screenshot? I’m not quite sure what you’re referring to.

 
Flag Post

Do these still work? My new game isn’t working with the high scores…

Edit) Wait nevermind… set it to flash player 8 and it’s all good.

 
Flag Post

Any hint on how to do it with actionscript 3.0? I’m guessing it might just be removing the underscores, but I’d rather be sure before submitting a non-working game.

 
Flag Post

Any hint on how to do it with actionscript 3.0? I’m guessing it might just be removing the underscores, but I’d rather be sure before submitting a non-working game.


AS3 is not yet supported, and there is much more involved than just removing the underscores. Support will come in time though.

 
Flag Post

Off-Topic:Hex you havn’t emailed me yet

Anyways, we can use the API for kongregate on our games on any game without asking kong.?

 
Flag Post

Anyways, we can use the API for Kongregate on our games on any game without asking kong.?

Yeah, you just follow the instructions in this thread.

 
Flag Post

Can someone help me with the score callback? So far I have:

_root.kongregateServices.connect();

var lvlscore = 1

var rawr = _root.kongregate_username

var scoresCallback:Function = function( result:Object ){

   	for( var i:Number = 0; i < result.list.length; i++ ){

	        if(result.list[i].username==rawr) {

			lvlscore = result.list[i].score

		}

	}

}

_root.kongregateScores.requestList( scoresCallback, this );

But lvlscore always seems to be 1… Bug in my script or bug in the High Scores API?
Could it be because I’m sending scores with _root.kongregateStats.submit(“CurrLevel”,level);?

 
Flag Post

Yes, Nabb, you can not retrieve arbitrarily named statistics with the high scores API as it follows a strict naming convention on the server. I do plan to add support to the statistics API for retrieving whatever statistics you want from the server, but unfortunately have higher priority stuff to work on at the moment :(

 
Flag Post

That would make sense :P Thanks. I’ll wait :P