Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411698 Posts in 69399 Topics- by 58454 Members - Latest Member: roeyskatt

May 19, 2024, 05:45:20 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Kongregate - Leaderboard not Showing
Pages: [1]
Print
Author Topic: Kongregate - Leaderboard not Showing  (Read 3258 times)
ChevyRay
Guest
« on: July 13, 2010, 03:54:48 AM »

Ugh, so sick of this already. Kongregate and it's madness, I don't even want to post on their forums because it'd be waste of life.

Here's the game: http://www.kongregate.com/games/ChevyRay/noggins

I set my game up to submit stats, and assigned the "Top Score" stat to appear on the leaderboards, but still no leaderboards are showing up.

KongAPI class (copied from AdamAtomic's FlxKong code) for connecting to the API. This is created first and added to the stage:

Code:
import flash.display.DisplayObject;
import flash.display.LoaderInfo;
import flash.display.Loader;
import flash.display.Sprite;
import flash.display.Stage;
import flash.net.URLRequest;
import flash.events.Event;

public class KongAPI extends Sprite
{
public function KongAPI()
{
addEventListener(Event.ADDED_TO_STAGE, init);
}

private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
var paramObj:Object = LoaderInfo(root.loaderInfo).parameters,
api_url:String = paramObj.api_path || "http://www.kongregate.com/flash/API_AS3_Local.swf",
request:URLRequest = new URLRequest(api_url),
loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded);
loader.load(request);
stage.addChild(loader);
}

private function loaded(e:Event = null):void
{
Main.KONG = e.target.content;
if (Main.KONG) Main.KONG.services.connect();
Main.NAME = Main.KONG.services.getUsername();
}
}

Then I just use this to submit stats when a game round ends:

Code:
if (!Main.KONG) return;
Main.KONG.stats.submit("Top Score", total);
Main.KONG.stats.submit("Top Headcount", heads);
Main.KONG.stats.submit("Top Accuracy", accuracy);
Main.KONG.stats.submit("Top Playtime", playtime);
Main.KONG.stats.submit("Total Score", total);
Main.KONG.stats.submit("Total Headcount", heads);
Main.KONG.stats.submit("Total Playtime", playtime);
Main.KONG.stats.submit("Latest Score", total);

It traces correctly that the submit call is being made, but other than that I have no idea why the leaderboards aren't appearing.
Logged
Terry
TIGSource Editor
Level 10
******



View Profile WWW
« Reply #1 on: July 13, 2010, 04:50:22 AM »

I've no idea what's going wrong there, it looks like it should work to me... Huh?

If this helps, here's my own current Kongapi class which works:

Code:
package {
import flash.display.LoaderInfo;
import flash.display.Loader;
import flash.display.Stage;
import flash.events.Event;
import flash.net.URLRequest;
import flash.system.Security;

public class kongapi {
public static var service:*;
public static var loadcomplete:Boolean;
public static var apitimeout:int;

public static function init(paramObj:Object, swfStage:Stage):void {
loadcomplete = false;
apitimeout = 60; loggedin = 0;
var api_url:String = paramObj.api_path || "http://www.kongregate.com/flash/API_AS3_Local.swf";
Security.allowDomain(api_url);
var request:URLRequest = new URLRequest(api_url);
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded);
loader.load(request);
swfStage.addChild(loader);
}

private static function loaded(event:Event):void {
loadcomplete = true;
service = event.target.content;
service.services.connect();
}

public static function guestcheck():void {
service.services.addEventListener("login", onKongregateInPageLogin);
}

public static function onKongregateInPageLogin(event:Event):void {
if (loggedin == 0) loggedin = 1;
}

public static function submit(name:String, value:int):void {
if(loadcomplete) service.stats.submit(name, value);
}

public static function getusername():String {
if (loadcomplete) return service.services.getUsername();
return "Guest";
}

public static function isguest():Boolean {
if (loadcomplete) return service.services.isGuest();
return true;
}
}
}

It sounds like you're doing everything right on the kongregate side: name all the stats, and set one to be a highscore. There's an old method that no longer works, which might be confusing google searches for you Sad
Logged

ishlilith
Level 0
**


View Profile WWW
« Reply #2 on: July 13, 2010, 05:13:02 AM »

I made this class to send scores to Kong, just call Kong.start(this) at the start of your code and Kong.submit("Your highscores name", score) when you want to submit the score. Make sure the highscores name matches the name you gave to the table in your game page.

http://blog.ishtories.com/kongregate-statistics-api-made-easy
Logged

Draknek
Level 6
*


"Alan Hazelden" for short


View Profile WWW
« Reply #3 on: July 13, 2010, 05:19:11 AM »

I just checked the only game I've put on Kongregate, and it now doesn't have a high score table either. And it definitely did a few weeks ago when I uploaded it. So maybe it's something weird going on with Kongregate's servers?
Logged

ChevyRay
Guest
« Reply #4 on: July 13, 2010, 05:32:29 AM »

I've just checked some games and they seem to work fine, though. I'm not going to just keep implementing different APIs if ones that work just fine for other games don't work for mine.

I thought that the leaderboard would show up simply because I assigned a statistic as a highscore in through the site's forms. So it should show up regardless of whether my code is submitting correctly or not, but it's not. GRgggg
Logged
Zachary Lewis
Level 1
*


Professional by day, indie by night.


View Profile WWW
« Reply #5 on: July 13, 2010, 05:53:11 AM »

I'm getting the notification that I'm getting a high score. When I was working on Space Junk, the table wouldn't show up for an hour or two. Here's what I did in FlashPunk (and it worked!).

So, Flash is pretty bad (especially when using a preloader) at knowing what the stage is sometimes. This problem is increased two-fold when you're talking with an API that is supposed to know whatever is going on at where (that sentence made as little sense as the Kong API does).

SO.

If you've got a preloader preloadin' your shit, you'll totally want to connect to the API then (the sooner, the better!). Here's my Preloader.as:

Code:
package 
{
import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.utils.getDefinitionByName;
import flash.text.TextField;
import flash.display.LoaderInfo;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.system.Security;

[SWF(width = "640", height = "480", bgcolor="0x111111")]

/**
* Preloads shit.
* @author Zachary Weston Lewis
*/
public class Preloader extends MovieClip
{
private var s:Sprite, p:Sprite, r:Sprite;
public function Preloader()
{
trace("Starting.");
addEventListener(Event.ENTER_FRAME, checkFrame);
loaderInfo.addEventListener(ProgressEvent.PROGRESS, progress);
// show loader
s = new Sprite;
s.graphics.beginFill(0xff00ff);
s.graphics.drawRect(0, 340 - 40, 640, 80);

addChild(s);

p = new Sprite;
p.graphics.beginFill(0xff00ff);
p.graphics.drawRect(0, 240 - 40, 640, 80);

addChild(p);

r = new Sprite;
r.graphics.beginFill(0xff00ff);
r.graphics.drawRect(0, 140 - 40, 640, 80);
GameProperties.GAME_STAGE = stage;
addChild(r);
api();
}

private function api():void
{
//Set up our... API?

// Pull the API path from the FlashVars
var paramObj:Object = LoaderInfo(GameProperties.GAME_STAGE.loaderInfo).parameters;

// The API path. The "shadow" API will load if testing locally.
var apiPath:String = paramObj.kongregate_api_path ||
 "http://www.kongregate.com/flash/API_AS3_Local.swf";

// Allow the API access to this SWF
Security.allowDomain(apiPath);

// Load the API
var request:URLRequest = new URLRequest(apiPath);
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
loader.load(request);
GameProperties.GAME_STAGE.addChild(loader);
}

// This function is called when loading is complete
private function loadComplete(event:Event):void
{
// Save Kongregate API reference
trace("LOADED");
GameProperties._API = event.target.content;

// Connect to the back-end
GameProperties._API.services.connect();

// You can now access the API via:
// kongregate.services
// kongregate.user
// kongregate.scores
// kongregate.stats
// etc...
}

private function progress(e:ProgressEvent):void
{
// update loader
p.x = -640 + 640 * loaderInfo.bytesLoaded / loaderInfo.bytesTotal;
s.x = 640 - 640 * loaderInfo.bytesLoaded / loaderInfo.bytesTotal;
r.x = 640 - 640*loaderInfo.bytesLoaded / loaderInfo.bytesTotal;

}

private function checkFrame(e:Event):void
{
if (currentFrame == totalFrames)
{
removeEventListener(Event.ENTER_FRAME, checkFrame);
startup();
}
}

private function startup():void
{
// hide loader
stop();
loaderInfo.removeEventListener(ProgressEvent.PROGRESS, progress);
var mainClass:Class = getDefinitionByName("Main") as Class;
addChild(new mainClass(stage) as DisplayObject);
}

}
}

Something good to know is that GamePropertites just as a bunch of static variables and constants. Also, GamePropertites._API is cast as a "*". So, I just connect to the API and shove that shit in there.

NOW. AND THEN, SO.

Once the player begins the game, I load up GameWorld and start tracking stats. Here's how I submit stuff (I update my stats every 15 seconds, just to prevent timeouts and stuff. Depending on your game style, you may want to only submit once a game. I like sending a bunch of shit, because if you get one bad submit, you don't lose everything.)

THIS:

Code:
private function updateScore():void
{
_submitTimer += FP.elapsed;
GameProperties.STAT_TIME_ALIVE += FP.elapsed;
if (_submitTimer > GameProperties.STAT_SUBMIT_TIME)
{
//Submit some shit.
submitScores();
resetScores(false);
}
}

private function submitScores():void
{
var _api:* = GameProperties._API;
if (_api != null)
{
trace("=======================================");
_api.scores.submit(GameProperties.WORLD_PLAYER_SCORE);
_api.stats.submit("Add_RoundsFired", GameProperties.STAT_ROUNDS_FIRED);
_api.stats.submit("Add_RamKills", GameProperties.STAT_RAM_KILLS);
_api.stats.submit("Add_DamageTaken", GameProperties.STAT_DAMAGE_TAKEN);
_api.stats.submit("Add_DamageDealt", GameProperties.STAT_DAMAGE_DEALT);
_api.stats.submit("Add_TreasuresOpened", GameProperties.STAT_TREASURES_OPENED);
_api.stats.submit("Add_OverloadedTurrets", GameProperties.STAT_OVERLOADED_TURRETS);
_api.stats.submit("Add_MisslesDowned", GameProperties.STAT_MISSLES_DOWNED);
_api.stats.submit("Add_ExperienceGained", GameProperties.STAT_EXPERIENCE_GAINED);
_api.stats.submit("Add_BossesKilled", GameProperties.STAT_BOSSES_KILLED);
_api.stats.submit("Max_BossesKilled", GameProperties.STAT_BOSSES_KILLED_SEQUENTIAL);
_api.stats.submit("Add_PointGuardsKilled", GameProperties.STAT_POINTGUARDS);
_api.stats.submit("Add_LastShadowsKilled", GameProperties.STAT_LASTSHADOWS);
_api.stats.submit("Add_QuadroniansKilled", GameProperties.STAT_QUADRONIANS);
_api.stats.submit("Add_HellfiresKilled", GameProperties.STAT_HELLFIRES);
_api.stats.submit("Add_DefendersKilled", GameProperties.STAT_DEFENDERS);
_api.stats.submit("Add_SpittersKilled", GameProperties.STAT_SPITTERS);
_api.stats.submit("Max_EnemiesKilled", GameProperties.STAT_ENEMIES_SEQUENTIAL);
_api.stats.submit("Max_TimeAlive", GameProperties.STAT_TIME_ALIVE);
_api.stats.submit("Max_Highscore", GameProperties.WORLD_PLAYER_SCORE);
_api.stats.submit("Max_Level", GameProperties.PLAYER_LEVEL);

}
}

private function resetScores(init:Boolean):void
{
if (init)
{
GameProperties.STAT_BOSSES_KILLED_SEQUENTIAL = 0;
GameProperties.STAT_ENEMIES_SEQUENTIAL = 0;
GameProperties.STAT_TIME_ALIVE = 0;
}
else
{
GameProperties.STAT_BOSSES_KILLED_SEQUENTIAL += GameProperties.STAT_BOSSES_KILLED;
GameProperties.STAT_ENEMIES_SEQUENTIAL += GameProperties.STAT_POINTGUARDS + GameProperties.STAT_LASTSHADOWS + GameProperties.STAT_QUADRONIANS +
GameProperties.STAT_HELLFIRES + GameProperties.STAT_DEFENDERS + GameProperties.STAT_SPITTERS;
}
GameProperties.STAT_ROUNDS_FIRED = 0;
GameProperties.STAT_RAM_KILLS = 0;
GameProperties.STAT_DAMAGE_TAKEN = 0;
GameProperties.STAT_DAMAGE_DEALT = 0;
GameProperties.STAT_TREASURES_OPENED = 0;
GameProperties.STAT_OVERLOADED_TURRETS = 0;
GameProperties.STAT_MISSLES_DOWNED = 0;
GameProperties.STAT_EXPERIENCE_GAINED = 0;
GameProperties.STAT_BOSSES_KILLED = 0;
GameProperties.STAT_POINTGUARDS = 0;
GameProperties.STAT_LASTSHADOWS = 0;
GameProperties.STAT_QUADRONIANS = 0;
GameProperties.STAT_HELLFIRES = 0;
GameProperties.STAT_DEFENDERS = 0;
GameProperties.STAT_SPITTERS = 0;
_submitTimer = 0;

GameProperties.PLAYER_LEVEL = 1;
}

So, that is things.

My guess is the preloader thing. Also, gotta' give it time to work its magic. Also, make sure you type 'em in the website right.
Logged

ChevyRay
Guest
« Reply #6 on: July 13, 2010, 06:02:43 AM »

Mmm nope, it's definitely getting a good stage reference, and it's definitely connecting (I've already logged and checked that). The highscore list just isn't appearing, which I thought it would do anyway, despite whether or not my code worked, since I've already told Kongregate.com that my game has stats and a highscore stat, no?

EDIT: Highscores JUST showed up. I guess it took some time before they activated? I don't recall reading that anywhere, but apparently it is so.
Logged
Zachary Lewis
Level 1
*


Professional by day, indie by night.


View Profile WWW
« Reply #7 on: July 13, 2010, 06:08:06 AM »

Yeah, I freaked my shit out for a good hour, changing my code and reuploading about ten times (which probably delayed the scores even longer).

Glad to see it's working! Fun game!
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic