Create the global newgrounds object
- Logs a view right away, for a guest and a logged in player alike, so a game does not have to
- Create the medals first: they take their name and icon from the server once it answers, and when logged in they are locked here until it does
- Call medalsInit too, before or after: an unlock asserts without it, and it keeps the medals while not logged in
app_id stringThe Newgrounds App ID
cipher string optionalThe encryption key from the app's settings, AES-128 as Base64; medal unlocks and posted
scores are encrypted with the browser's WebCrypto, which needs a secure page, https or localhost
// create the newgrounds object, replace the app id with your own
const app_id = 'your_app_id_here';
new NewgroundsPlugin(app_id);
AES-128/Base64 encryption key, if any
Hostname sent with the view the plugin logs when it starts
Medals fetched from Newgrounds, empty until ready, with the unlocks only when logged in
Medals whose unlock is in flight or waiting to be resent, with their request's promise; one the server refused leaves it
Resolves once the session is checked and the lists are in, empty if the server could not be reached
Scoreboards fetched from Newgrounds, empty until ready
Newgrounds session id from the URL, null when not logged in or once the session is lost
The logged in player once ready, null when not logged in
Send a message to call a component of the Newgrounds API
component stringName of the component
parameters Object optionalParameters to use for call
session_id string|null optionalThe session to send, the player's by default
- Returns
- The response JSON object, undefined when the call failed or took over 15 seconds;
a component's own success and error are in result.data, and a cipher that is not a key gives error 201
Load the value a cloud save slot holds: null when Newgrounds says it holds none, undefined when it could not be
loaded or the player is not logged in, said in the console when logged in
- Do not save over a slot that loaded as undefined, it may hold the player's save; loadFailure(slot) says why
it did: 'notSave' for a file there that is not a save, where a game may offer to start over, 'failed' otherwise
- A saved null loads as null, as an empty slot does
slot numberThe slot number
- Returns
- The value saved, null for none, undefined for a load that failed
const save = await newgrounds.cloudLoad(1);
Save a value to one of the player's cloud save slots, which needs a logged in player
- Any value JSON can hold; the slots are numbered from 1, as many as the app's Newgrounds settings give it
slot numberThe slot number
data *The value to save
- Returns
- Whether it saved, false when not logged in
newgrounds.cloudSave(1, {level, coins});
Encrypt text the way the Newgrounds gateway expects, AES-128 CBC with a random iv in front, as Base64
text string
Get scores from a scoreboard
id numberThe scoreboard id
user string|number optionalA user's id or name, to load only their scores
social boolean optional, default falseIf true, only the scores of the user and their friends, the logged in player when user is left out
skip number optional, default 0Number of scores to skip over
limit number optional, default 10Number of scores to include in the list
period string optional'D' today, which the server assumes when left out, 'W' this week, 'M' this month, 'Y' this year or 'A' all time
- Returns
- The response JSON object, undefined when the call failed; the scores are in
result.data.scores, each with user.name, value and formatted_value; without a user or social it is the whole board
Why a slot's last cloudLoad gave undefined: 'notSave' when the slot holds a file that is not a save, where a
game may offer to start over, 'failed' when it could not be loaded, as when not logged in, where a game must
not save over it; undefined when it loaded a save or found the slot empty, or was not loaded
slot numberThe slot number
Count an event of the game's own on its Newgrounds stats page, like a level finished or a button pressed
name stringThe event's name
- Returns
- The response JSON object, undefined when the call failed
Send message to post score
id numberThe scoreboard id
value numberThe score value, a whole number
- Returns
- The response JSON object, undefined when the call failed; result.data.success says whether
it posted, which needs a logged in player; an answer that the session is gone makes the game play as not logged
in, and one that timed out may still have posted
Send the unlocks whose request did not reach the server again, which the session check does every minute
- A request still out is left to answer, and while unlocks are prevented they wait
Send a request to unlock a medal by id, the local medal is not changed; NewgroundsMedal.unlock sends this and waits for the answer
id numberThe medal id
- Returns
- The response JSON object, undefined when the call failed