PlayerIO

The fastest way to build online games without breaking a sweat.

HTML5 (Javascript) Client Reference

javascript (html5) achievements class informationClass achievements

Language: Javascript (HTML5)

The Achievements service. This class is used to update the progress of an achievement for the current user, and loading achievements of other users. All achievements have to be defined in the admin panel first.

Example

Refresh to get the user's current achievements and the progress of each:

Example

Load achivements for other users:

Example

Set the progress of the achievement "fiveinarow" to 2.

Properties

 
myAchievements :achievement[]

The list of achievements for the current user. You must call refresh() first to initialize this list.

Methods

 
addOnComplete (onComplete):

Add an OnComplete event handler that will be called every time an achievement is completed.

get (achievementId):

Get an achievement by id

load (userIds, successCallback, errorCallback):

Load the achivements for multiple users by their connectUserId

progressAdd (achievementId, progressDelta, successCallback, errorCallback):

Adds the delta to the progress of the specified achievement

progressComplete (achievementId, successCallback, errorCallback):

Completes the specified achievement by setting the progress to the progress goal.

progressMax (achievementId, progress, successCallback, errorCallback):

Sets the progress of the specified achievement to the bigger value of the current value and the given value.

progressSet (achievementId, progress, successCallback, errorCallback):

Sets the progress of the specified achievement

refresh (successCallback, errorCallback):

Refresh the list of achievements.

achievements.myAchievements

myAchievements :achievement[]

The list of achievements for the current user. You must call refresh() first to initialize this list.

achievements.addOnComplete

addOnComplete (onComplete):

Add an OnComplete event handler that will be called every time an achievement is completed.

Arguments

onComplete:function(achievement)
The function to add.

achievements.get

get (achievementId):

Get an achievement by id

Arguments

achievementId:string
Id of the achievement to get.

achievements.load

load (userIds, successCallback, errorCallback):

Load the achivements for multiple users by their connectUserId

Arguments

userIds:string[]
The list of users to load achievements for.
successCallback:function(result)
Callback function that will be called with the loaded achievements.
errorCallback:function(PlayerIOError)
Callback function that will be called if an error occurs.

achievements.progressAdd

progressAdd (achievementId, progressDelta, successCallback, errorCallback):

Adds the delta to the progress of the specified achievement

Arguments

achievementId:string
The id of the achievement to add to the progress for.
progressDelta:Number
The value to add to the progress.
successCallback:function(achievement)
Callback function that will be called when the operation has completed.
errorCallback:function(PlayerIOError)
Callback function that will be called if an error occurs.

achievements.progressComplete

progressComplete (achievementId, successCallback, errorCallback):

Completes the specified achievement by setting the progress to the progress goal.

Arguments

achievementId:string
The id of the achievement to complete.
successCallback:function(achievement)
Callback function that will be called when the operation has completed.
errorCallback:function(PlayerIOError)
Callback function that will be called if an error occurs.

achievements.progressMax

progressMax (achievementId, progress, successCallback, errorCallback):

Sets the progress of the specified achievement to the bigger value of the current value and the given value.

Arguments

achievementId:string
The id of the achievement to set the progress for.
progress:Number
The value to set the progress to, if it's bigger than the current value.
successCallback:function(achievement)
Callback function that will be called when the operation has completed.
errorCallback:function(PlayerIOError)
Callback function that will be called if an error occurs.

achievements.progressSet

progressSet (achievementId, progress, successCallback, errorCallback):

Sets the progress of the specified achievement

Arguments

achievementId:string
The id of the achievement to set the progress for.
progress:Number
The value to set the progress to
successCallback:function(achievement)
Callback function that will be called when the operation has completed.
errorCallback:function(PlayerIOError)
Callback function that will be called if an error occurs.

achievements.refresh

refresh (successCallback, errorCallback):

Refresh the list of achievements.

Arguments

successCallback:function()
Callback function that will be called when the refresh is complete
errorCallback:function(PlayerIOError)
Callback function that will be called if an error occurs