Full Documentation
Clay.Achievement
Overview
Contains methods for anything related to Clay.io achievements. Must be instantiated with "new"
Methods
constructor
-
Parameters
-
Example
-
new Clay.Achievement( { id: 1 } );
-
award
Awards this object's achievement to a user. If they aren't logged into a Clay.io account, it is stored with their IP Address and granted to them when they signup.-
Parameters
-
Example
-
( new Clay.Achievement( { id: 1 } ) ).award( function( response ) { if( response.success ) console.log( response.title + ": " response.description ) else console.log( "Error: " + response.error ); };
-
showAll
Fetches all the achievements you've created for this game, and if the player has earned them or not. This is good motivation for users to try and get the remaining achievements-
Parameters
-
Example
-
Clay.Achievement.fetchAll( {}, function( response ) { console.log( response ); } );
-
fetchAll
Shows all the achievements you've created for this game, and if the player has earned them or not. This is good motivation for users to try and get the remaining achievements-
Example
-
Clay.Achievement.showAll();
-
Clay.Advertisement
Overview
Methods
constructor
Creates and displays an advertisement-
Parameters
-
Example
-
new Clay.Advertisement( { size: '125x125', position: { left: 50%, top: 50% } } );
-
show
Call to show the advertisementhide
Call to hide the advertisementrefresh
Call to load a new advertisement in the same place. Works once every 30 seconds maxsetPosition
Move the advertisement after you've intiated it-
Parameters
-
[required] (object) position Positioning for the ad. Pass two of the properties:
left,right,top,bottom.
Pass a static number for pixels, or a relative number followed by a %
Passing 'center' as thereferenceproperty, withleft: 50%,top: 50%will center the ad
Theparentproperty defaults to document, but can be set to a DOM element to position relative to the canvas
-
-
Example
-
advertisement.setPosition( { left: 50%, top: 50% } );
-
Clay.Facebook
Overview
Methods
constructor
There are no arguments to pass in the constructorpost
Posts a new stream item to Facebook. The user must be logged into Clay, and has granted your game permission to post to their Facebook stream. If the user is either not logged in, or hasn't granted permission, Clay.io will take care of all of that for you.-
Parameters
-
Example
-
( new Clay.Facebook() ).post( { message: "Testing!" }, function( response ) { if( !response.success ) console.log( "Error: " + response.error ); };
-
invite
Connects with Facebook and lists the user's friends, allowing them to individually select friends to invite to play your game. Once they hit the "Invite" button, a message will be posted on their friends wall telling them about your game.-
Parameters
-
Example
-
Clay.Facebookinvite( { caption: "Come play me in this sweet game!" }, function() { console.log( "Successfully posted!" ); };
-
Clay.Leaderboard
Overview
Methods
constructor
-
Parameters
-
Example
-
new Clay.Leaderboard( { id: 1, tabs: [{ id: 2 }] } );
-
fetch
Retrieves an array of leaderboard objects (name, score) If getRank is set to true, the response is an object with { data: [objects], rank: { rank: int, row: object } }-
Parameters
-
Example
-
( new Clay.Leaderboard( { id: 1 } ) ).fetch();
-
show
Show the leaderboard modal window-
Parameters
-
Example
-
( new Clay.Leaderboard( { id: 1 } ) ).show();
-
hide
Hides the leaderboard modal-
Example
-
leaderboard.hide();
-
setTabs
Sets tabs for the leaderboard-
Parameters
post
Posts a score the this leaderboard object-
Parameters
-
Example
-
( new Clay.Achievement( { id: 1 } ) ).award( function( response ) {
-
Clay.Payment
Overview
Methods
addItem
Adds an item to the user's cart-
Parameters
-
Example
-
(new Clay.Payments()).addItem( { id: 1 }, function( response ) { console.log( response ); }
-
getItemIds
Fetches the ids of items the user playing your game 'owns'-
Return
removeItem
Removes an item from the users cart. If the quantity is greater than one, it just reduces the quantity by 1-
Parameters
checkout
Initiates the checkout sequence within Clay.io where the user is asked to confirm the purchase, then directed through the payment processors-
Parameters
Clay.Ratings
Overview
Methods
constructor
Call to open the ratings modal. The ratings modal lets users rate and comment on your game.-
Parameters
-
Example
-
new Clay.Ratings()
-
Clay.Rooms
Overview
Methods
constructor
Instantiates the Rooms object-
Parameters
show
Shows the rooms list modal-
Parameters
getRooms
Fetches an array of all rooms currently created-
Return
createRoom
Allows you to manually create the room (the modal flow provides all of this for a user, so this is just if you want to manually create one)-
Parameters
joinRoom
Allows you to manually have a user join a room-
Parameters
leaveRoom
Allows you to manually remove a user from a room-
Parameters
Clay.Screenshot
Overview
Methods
constructor
Instantiates the Screenshot object and starts the flow unless you specify otherwise-
Parameters
-
Example
-
new Clay.Screenshot();
-
prompt
Manually call the prompt modal to show (prompts a user to save screenshot to Clay.io)save
Manually saves a screenshot to the Clay.io server (and is associated with the user's account)-
Parameters
-
Example
-
( new Clay.Screenshot() ).save( function( response ) { console.log( response ); } );
-
Clay.Stats
Overview
Methods
log
Logs a custom statistic. The graph can be viewed in the developer area for your game, under 'stats'-
Parameters
-
Example
-
Clay.Stats.logStat( 'talkedToNPC', 1 );
-
level
For statistics associated with game levels. You can start and end levels to gather statistics on dropout rate, time to complete, etc...-
Parameters
-
Example
-
Clay.Stats.level( { action: 'start', level: 1 } );
-
Clay.Stream
Overview
Methods
post
Posts a message to the user's Clay.io stream. They must be logged in for this to work. A login flow is brought up if they are not logged in-
Parameters
-
Example
-
( new Clay.Stream() ).post( { message: "Testing!", function( response ) { if( !response.success ) console.log( "Error: " + response.error ); };
-
Clay.Suggestions
Overview
Methods
constructor
Call to open the suggestions modal. The game suggestions modal displays 3 recommended games. Each time one is clicked you earn credits that will get you clicks to your game from others. More info [here](http://clay.io/docs/suggestions)-
Parameters
-
Example
-
new Clay.Suggestions()
-
Clay.Twitter
Overview
Methods
constructor
There are no arguments to pass in the constructorpost
Posts a Tweet. The user must be logged into Clay, and has granted your game permission to post to their Twitter Account. If the user is either not logged in, or hasn't granted permission, Clay.io will take care of all of that for you.-
Parameters
-
Example
-
( new Clay.Twitter() ).post( { message: "Testing!", function( response ) { if( !response.success ) console.log( "Error: " + response.error ); };
-
Clay.UI
Overview
Contains methods for anything related to User Interface.
Click here for our Article Page on UI
Methods
modalsOpen
Returns the number of Clay.io modals that are currently open-
Return
notificationsOpen
Returns the number of Clay.io notifications that are currently open-
Return
closeModal
Closes the most recently opened modal window, or the id passed in options-
Parameters
getDocumentSize
-
Return
getWindowSize
-
Return
createModal
Creates and displays a modal window-
Parameters
-
Example
-
Clay.UI.createModal( { title: 'Title', html: "<div>Here's some HTML</div>" } )
-
updateModal
Updates a modal window-
Parameters
-
Example
-
Clay.UI.updateModal( { title: 'Title', html: "<div>Here's some HTML</div>" } )
-
createNotification
Creates and displays a notification message (this is used for things like achievements).-
Parameters
-
Example
-
Clay.UI.createNotification( { title: 'Title', html: "<div>Here's some HTML</div>" } )
-
closeNotification
Closes a notification-
Parameters
-
[required] (string) id DOM id assigned to wrapper (it's assigned as "clay-" + type + "-" + id)
-
addToContainer
Adds an element to the clay container div-
Parameters
-
[required] (string) id DOM id assigned to wrapper (it's assigned as "clay-" + type + "-" + id)
-
Clay.Player
Overview
Methods
setUsername
Gives the player a custom name, instead of Anonymous if they're not logged into Clay.io. By default, the user is able to choose this in the Clay login modal-
Parameters
-
[required] (string) username The name you want to give them (will show up on things like leaderboards)
-
saveUserData
Saves the specified saved user data to the server Note: you cannot save data under the keys "user", "game", or "_id" Usage: User.saveUserData('level1Score', '51000', function( response ) { console.log( response.success ); } ... $ true-
Parameters
-
(string) key the key that you'd like to save the data to
-
(object) data JSON-safe data for saving
-
fetchUserData
Grabs the specified saved user data from the server Usage: User.fetchUserData('level1Score', function( repsonse) { console.log( response.data ); } ) ... $ '51000'-
Parameters
-
(string) key the key specifying the data you'd like to fetch
-
fetchItems
Grabs all the items this player has in your game-
Parameters
grantItem
Grants the user an item (created in the developer dashboard for your game)-
Parameters
removeItem
Removes an item from the player's inventory-
Parameters
purchaseGame
If this isn't a free game, let them buy the game from within your game This is equivalent to adding an item with type: 'game', id: gameID, and calling checkout-
Parameters
hasInstalled
-
Return
onUserReady
Called when the user is logged in (and we have a name for them)-
Parameters
login
Manually triggers the flow for a user to login, signup, or enter their name within the modal window-
Parameters
-
[optional] (boolean) signup If set to true, the signup tab is opened initially (rather than login)
-
signup
Manually triggers the flow for a user to signup, within the modal window. Alias for Clay.Player.login( callback, true );-
Parameters
requireLogin
Does a check if they're logged in - calls the callback if they are, forces them to login if they aren't (then calls the callback after login) Use this for anything is your game where you need the user to be logged in-
Parameters
-
[optional] (boolean) requireLoggedIntoClay Set true if you only want this called if they are logged into a clay.io account (ie they aren't anonymously 'logged in' with just their name)
-
Provide Feedback
We take customer support, and the quality of our developer tools and documentation very seriously. We want to hear how you think we can improve our documentation! Let us know if anything is missing, or unclear on this documentation page, and we'll get that fixed!