Hobbies And Interests

How to Make a Scoreboard on a Newgrounds Game

Newgrounds is a social media website that enables users to create and upload Flash games. Such versatility has attracted many gamers, who have created thousands of online games anybody can play. One of the core components of any online competitive game is the scoreboard, which enables players to compare their high scores against those of other players. While coding the actual game may be easy for some, coding the game to interface with the Internet can be more difficult.

Instructions

    • 1

      Create a new scoreboard on the website's API by filling out the form in the accounts tab.

    • 2

      Access the code for the scoreboard from the account.

    • 3

      In the following code, change "board_name" to the name of the scoreboard you created.

      import com.newgrounds.API;

      import com.newgrounds.ScoreBoard;

      var board:ScoreBoard = API.getScoreBoard(board_name:String);

    • 4

      Input this code into the scoreboard script:

      import com.newgrounds.API;

      import com.newgrounds.APIEvent;

      import com.newgrounds.ScoreBoard;

      import com.newgrounds.Score;

      // this function will run when the server returns our list of scores

      function onScoresLoaded(event:APIEvent):void {

      if (event.success) {

      var board = event.data.board;

      for(var i:uint=0; i<board.scores.length; i++) {

      var score:Score = board.scores[i];

      trace(score.position+": "+score.username+" -- "+score.value);

      }

      }

      // Tell the api to listen for the SCORES_LOADED event

      API.addEventListener(APIEvent.SCORES_LOADED, onScoresLoaded);

      // get our board and tell it what time period to load up, and how many results

      var high_scores:ScoreBoard = API.getScoreBoard("High Scores");

      high_scores.period = "Today";

      high_scores.num_results = 20;

      // load the scores from the server

      high_scores.loadScores();

    • 5

      Input the following code to load the high scores in a game:

      import com.newgrounds.API;

      API.loadScores(board_name:String, period:String, tag:String);

    • 6

      Replaced the "board_name" with the name of your scoreboard and the "period" to the time period.


https://www.htfbw.com © Hobbies And Interests