00:00
00:00
Newgrounds Background Image Theme

Someone gifted Template88 supporter status!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

getting all pages

352 Views | 7 Replies
New Topic Respond to this Topic

getting all pages 2014-04-01 14:59:27


I'm trying to grab all of the highscores from the newgrounds API, I can see in the game page there's at least 2 pages. but the code below just seems to show the first page an infinite number of times, crashing the game. How to I get ALLLLL of the names?

var allScores:Vector.<Score> = new <Score>[];
			
while (_highScores.scores.length > 0) {
	
	for each(var score:Score in _highScores.scores)
		allScores.push(score);
	
	_highScores.nextPage();
}

Response to getting all pages 2014-04-01 15:03:40


More info: the first page contains 10 scores, there are currently 20 scores up. I tried prevPage too, thinking maybe it starts on the last page, that didn't work

Response to getting all pages 2014-04-01 15:20:12


the condition of the while loop depends on the length of an array that you never change, that's why it crashes.

Response to getting all pages 2014-04-01 15:33:17


At 4/1/14 03:20 PM, milchreis wrote: the condition of the while loop depends on the length of an array that you never change, that's why it crashes.

I'm under the assumption that nextPage() changes the value of scores. since there's no other accessors for score data, do I have to call nextPage(), followed by a loadScores()? Does it just send down all of the scores on the first loadScores() call? I guess bigger games would have a hefty initial load if it sent them all down.

Response to getting all pages 2014-04-01 16:05:41


Nevermind, this fixed it

_highScores.numResults = uint.MAX_VALUE;
_highScores.addEventListener(APIEvent.SCORES_LOADED, onScoresLoaded);
_highScores.loadScores();

I can probably get an infinite number of results if I do the nextPage() before a loadScores() call. but I don't think I have to worry.

Response to getting all pages 2014-04-01 16:46:30


At 4/1/14 03:33 PM, GeoKureli wrote: have a hefty initial load if it sent them all down.

name and value pairs, that's not a big deal

The documentation says that scores contains all scores of the last query, so I guess this is wrong?
Do you still use the pages?

Response to getting all pages 2014-04-01 17:22:31


At 4/1/14 04:46 PM, milchreis wrote:
At 4/1/14 03:33 PM, GeoKureli wrote: have a hefty initial load if it sent them all down.
name and value pairs, that's not a big deal

The documentation says that scores contains all scores of the last query, so I guess this is wrong?

not really, I just have to specify the query size.

Do you still use the pages?

No, all one single page; I'm pretty sure I would use pages to get a query from like: 20-40

Response to getting all pages 2014-04-01 17:28:51


At 4/1/14 05:22 PM, GeoKureli wrote:
At 4/1/14 04:46 PM, milchreis wrote: The documentation says that scores contains all scores of the last query, so I guess this is wrong?
not really, I just have to specify the query size.

did I mention the last code I posted is called before I check scores?