Full Documentation

Clay.Achievement

Overview

Contains methods for anything related to Clay.io achievements. Must be instantiated with "new"

Methods

constructor
  • Parameters
    • [required] (object) options

      • (int) id Integer achievement ID. Given in developer dashboard for game after creating the achievement

      • (string) jwt JSON Web Token (hashed object) if you have the encryption option on for your game

  • 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
    • [optional] (function) callback

      • (object) response

        • (bool) success true if achievement awarded, false otherwise

        • (truthy) error Boolean false if no error, String error message if error

        • (string) title Title of the achievement that was awarded

        • (string) description Description of the achievement that was awarded

        • (int) points The amount of points the achievement is worth

        • (truthy) icon False if no icon specified (in developer dashboard) or the full URL to the icon if it was specified

        • (boolean) showExternally This is false if you set the option (in developer dashboard) to hide achievements when not playing from the Clay subdomain, true otherwise

  • 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
    • [optional] (object) options - none to specify yet

    • [optional] (function) callback

      • (object) response

        • (bool) success true if achievement awarded, false otherwise

        • (truthy) error Boolean false if no error, String error message if error

        • (string) title Title of the achievement that was awarded

  • 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
    • [required] (object) options

      • (string) size Size of the ad. Choose from '160x600', '728x90', '300x250', '120x600', '200x200', '468x60', '125x125'

      • (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 the reference property, with left: 50%, top: 50% will center the ad
        The parent property defaults to document, but can be set to a DOM element to position relative to the canvas

      • (integer) refreshInterval Number of seconds to refresh the ad after. Must be a value greater than 30 seconds

  • Example
    • new Clay.Advertisement( { size: '125x125', position: { left: 50%, top: 50% } } );
show
Call to show the advertisement
    hide
    Call to hide the advertisement
      refresh
      Call to load a new advertisement in the same place. Works once every 30 seconds max
        setPosition
        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 the reference property, with left: 50%, top: 50% will center the ad
            The parent property 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 constructor
          post
          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
            • [required] (object) options You can pass any any of the options listed here

              • (string) message A message to post (note, not all options are listed here, be sure to see the Facebook API docs linked to above)

              • (boolean) editable If set to true, the user will be able to edit the message they are posting

            • [optional] (function) callback

              • (object) response

                • (bool) success true if stream message was posted, false otherwise

                • (truthy) error Boolean false if no error, String error message if error

          • 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
            • [required] (object) options

              • (string) caption The message that is posted to the users wall (along with a link to your game and the game's description). By default this is "Come play GAMENAME with me!"

              • (string) id DOM element id. If passed, the invite iframe will be put in that element. If not passed, it will be opened in the modal window.

            • [optional] (function) callback Called when at least one invite is successfully sent

          • Example
            • Clay.Facebookinvite( { caption: "Come play me in this sweet game!" }, function() {
              	console.log( "Successfully posted!" );
              };

          Clay.Game

          Overview

          Methods

          getData
          • Return
            • an object of data pertaining to your game
              { id: (int) game ID, name: (string) name of game }

          Clay.Leaderboard

          Overview

          Methods

          constructor
          • Parameters
            • [required] (object) options

              • (int) id Integer leaderboard ID. Given in developer dashboard for game after creating the leaderboard

              • (string) jwt JSON Web Token (hashed object) if you have the encryption option on for your game

              • (array) tabs An array of tab objects (a tab object can contain any of the options a typical leaderboard contains: id, data, filter, etc)

              • (string) html Custom HTML to show at the top of the leaderboard modal

              • (int) recent Specify an integer of seconds in the past to display scores from. ex. 3600 would show the last hour of scores

              • (array) filter An array of filters, similar to tabs, but can specify just a string for certain time intervals. ex. ['day', 'month', { title: "Custom Interval", recent: 7200 }]

              • (int) limit How many scores to show

              • (boolean) self Shows only scores by the person viewing the leaderboard if set to true

              • (boolean) friends Shows only scores by the friends of the person viewing the leaderboard if set to true

              • (boolean) cumulative Sums up all scores per unique person over the given interval

              • (boolean) showPersonal Displays personal stats like their best rank and score

          • 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
            • [required] (object) options If you pass these in the constructor, you don't need to again here

              • (int) id Integer leaderboard ID. Given in developer dashboard for game after creating the leaderboard

              • (int) recent Specify an integer of seconds in the past to fetch scores from. ex. 3600 would return the last hour of scores

              • (int) limit How many scores to show

              • (boolean) self Returns only scores by the person viewing the leaderboard if set to true

              • (boolean) friends Returns only scores by the friends of the person viewing the leaderboard if set to true

              • (boolean) cumulative Sums up all scores per unique person over the given interval

              • (boolean) getRank If true, this method returns an object instead of an array. The object consists of the data property that is the array of score objects, and a rank object that contains an integer rank property, and an object row property holding score and name

          • Example
            • ( new Clay.Leaderboard( { id: 1 } ) ).fetch();
          show
          Show the leaderboard modal window
          • Parameters
            • [required] (object) options If you pass these in the constructor, you don't need to again here

              • (int) id Integer leaderboard ID. Given in developer dashboard for game after creating the leaderboard

              • (array) tabs An array of tab objects (a tab object can contain any of the options a typical leaderboard contains: id, data, filter, etc)

              • (string) html Custom HTML to show at the top of the leaderboard modal

              • (string) sort Accepts 'asc' or 'desc' to sort the scores either ascending or descending

              • (int) recent Specify an integer of seconds in the past to display scores from. ex. 3600 would show the last hour of scores

              • (array) filter An array of filters, similar to tabs, but can specify just a string for certain time intervals. ex. ['day', 'month', { title: "Custom Interval", recent: 7200 }]

              • (int) limit How many scores to show

              • (boolean) self Shows only scores by the person viewing the leaderboard if set to true

              • (boolean) friends Shows only scores by the friends of the person viewing the leaderboard if set to true

              • (boolean) cumulative Sums up all scores per unique person over the given interval

              • (boolean) showPersonal Displays personal stats like their best rank and score

          • Example
            • ( new Clay.Leaderboard( { id: 1 } ) ).show();
          hide
          Hides the leaderboard modal
          • Example
            • leaderboard.hide();
          setTabs
          Sets tabs for the leaderboard
          • Parameters
            • [required] (object) options

              • (array) An array of tabs objects

          post
          Posts a score the this leaderboard object
          • Parameters
            • [required] (object) options

              • (int) score

              • (string) name - If a name is passed, it will be used in the name column. Otherwise Clay.io will request login/their name to use (if not logged in)

              • (boolean) hideUI - if set to true, the leaderboard posted notification will not show

            • [optional] (function) callback

              • (object) response

                • (bool) success true if score was posted, false otherwise

                • (truthy) error Boolean false if no error, String error message if error

          • Example
            • ( new Clay.Achievement( { id: 1 } ) ).award( function( response ) {

          Clay.Payment

          Overview

          Methods

          addItem
          Adds an item to the user's cart
          • Parameters
            • [required] (object) options

              • (int) id Item ID. Given in developer dashboard for game after creating the item

            • [optional] (function) callback called when item has been added to cart

              • (object) response

                • (bool) success true if item was successfuly added, false otherwise

                • (truthy) error Boolean false if no error, String error message if error

          • 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
            • (array) items Array of item ids. Ex. [1, 5, 6, 7]

          removeItem
          Removes an item from the users cart. If the quantity is greater than one, it just reduces the quantity by 1
          • Parameters
            • [required] (object) options

              • (int) id Item ID. Given in developer dashboard for game after creating the item

          checkout
          Initiates the checkout sequence within Clay.io where the user is asked to confirm the purchase, then directed through the payment processors
          • Parameters
            • [optional] (object) options

              • (string) id Specify if you do not want to use the standard Clay.io UI. Pass the DOM element ID you want the payment box to go in

            • [optional] (function) callback Called when either purchase has successfully gone through, or if there was an error/canceled process

              • (object) response

                • (bool) success True if the user went through the whole process without generating an error

                • (truthy) error Boolean false if no error, String error message if error

                • (string) status Info about the payments current status (ex. pending) - this still needs to be normalized on our end. Give us a nudge if we haven't done it yet

                • (bool) completed Boolean if the payment was approved right away or not

                • (array) itemIds Array of Integers: The items they ended up purchasing - this could be different than the items you pass since they can optionally remove items

          Clay.Ratings

          Overview

          Methods

          constructor
          Call to open the ratings modal. The ratings modal lets users rate and comment on your game.
          • Parameters
            • [required] (object) options

              • (int) id DOM element id. If passed, the rating iframe will be put in that element. If not passed, it will be opened in the modal window.

          • Example
            • new Clay.Ratings()

          Clay.Rooms

          Overview

          Methods

          constructor
          Instantiates the Rooms object
          • Parameters
            • [optional] (function) fullCallback Called when a room is full (for any user)

              • (object) response

                • (bool) success true if the room was successfully created, false otherwise

                • (truthy) error Boolean false if no error, String error message if error

                • (int) id A unique ID of the room that was created, starting from 0

                • (int) count The number of people in the room

                • (int) max The maximum number of players allowed in a room (specified in Developer Game Settings)

                • (object) instance A reference to the Clay.Rooms instance (so you can use response.instance.leaveRoom() if you'd like)

                • (string) name The name created by a user for the room

          show
          Shows the rooms list modal
          • Parameters
            • [optional] (function) callback Called when the rooms modal is done loading

              • rooms (array) Array of all non-full rooms. Each array element contains objects with the following properties

                • (int) count Number of players currently in the room

                • (int) id Unique ID of the room

                • (int) max The maximun number of users allowed in the room

                • (array) members Array of objects with the property name being their name

                • (string) name The name of the room

          getRooms
          Fetches an array of all rooms currently created
          • Return
            • (array) Array of all non-full rooms. Each array element contains objects with the following properties

              • (int) count Number of players currently in the room

              • (int) id Unique ID of the room

              • (int) max The maximun number of users allowed in the room

              • (array) members Array of objects with the property name being their name

              • (string) name The name of the room

          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
            • [optional] (object) options

              • (string) name The name of the room. If left blank, it grabs the value from the rooms text field

            • [optional] (function) callback Called when room is created

              • room (array) An object with the following properties

                • (int) count Number of players currently in the room

                • (int) id Unique ID of the room

                • (int) max The maximun number of users allowed in the room

                • (array) members Array of objects with the property name being their name

                • (string) name The name of the room

          joinRoom
          Allows you to manually have a user join a room
          • Parameters
            • [optional] (object) options

              • (int) id The ID of the room for them to join

            • [optional] (function) callback Called when room is joined

              • room (array) An object with the following properties

                • (int) count Number of players currently in the room

                • (int) id Unique ID of the room

                • (int) max The maximun number of users allowed in the room

                • (array) members Array of objects with the property name being their name

                • (string) name The name of the room

          leaveRoom
          Allows you to manually remove a user from a room
          • Parameters
            • [optional] (object) options

              • (int) id The ID of the room for them to join

            • [optional] (function) callback Called when room is joined

              • (object) response

                • (bool) success true if the user was successfully removed from the room, false otherwise

                • (truthy) error Boolean false if no error, String error message if error

          Clay.Screenshot

          Overview

          Methods

          constructor
          Instantiates the Screenshot object and starts the flow unless you specify otherwise
          • Parameters
            • [optional] (object) options

              • (boolean) prompt Set to false if you don't want the Screenshot flow to start when instantiating (ie you want to do something with the screenshot in the background)

          • 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
              • [optional] (object) options

                • (string) id By default, we select the first canvas on the page to take a screenshot of -- you can specify a different canvas by passing the DOM id

                • (boolean) prompt Set to false if you don't want the Screenshot flow to start when instantiating (ie you want to do something with the screenshot in the background)

              • [optional] (function) callback Called when response is received from server

                • (object) response

                  • (bool) success true if the screenshot was successfully posted, false otherwise

                  • (truthy) error Boolean false if no error, String error message if error

                  • (string) url URL pointing to the screenshot page on Clay.io

                  • (string) imageSrc Direct URL to the image

            • 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
              • [required] (object) options

                • (string) name The name/key to associate this stat with

                • (int) quantity Defaults to 1 -- a value to associate with the stat

            • 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
              • [required] (object) options

                • (string) action One of: 'start', 'pass', 'fail'

                • (string) level A unique identifier for the current level

            • 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
              • [required] (object) options

                • (string) message The stream message to post

                • (boolean) editable If set to true, the user will be able to edit the message they are posting

              • [optional] (function) callback

                • (object) response

                  • (bool) success true if message was posted, false otherwise

                  • (truthy) error Boolean false if no error, String error message if error

            • 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
              • [required] (object) options

                • (int) id DOM element id. If passed, the rating iframe will be put in that element. If not passed, it will be opened in the modal window.

            • Example
              • new Clay.Suggestions()

            Clay.Twitter

            Overview

            Methods

            constructor
            There are no arguments to pass in the constructor
              post
              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
                • [required] (object) options

                  • (boolean) editable If set to true, the user will be able to edit the message they are posting

                  • (string) message A <= 140 character long message to tweet

                • [optional] (function) callback

                  • (object) response

                    • (bool) success true if tweet was posted, false otherwise

                    • (truthy) error Boolean false if no error, String error message if error

              • 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
                • (int) number of modals open

              notificationsOpen
              Returns the number of Clay.io notifications that are currently open
              • Return
                • (int) number of notifications open

              closeModal
              Closes the most recently opened modal window, or the id passed in options
              • Parameters
                • [optional] (object) options

                  • (string) id The DOM id of the modal to close (ex. clay-login-wrapper)

              getDocumentSize
              • Return
                • (object) DOM document 'height' and 'width' in pixels

              getWindowSize
              • Return
                • (object) Window 'height' and 'width' in pixels

              createModal
              Creates and displays a modal window
              • Parameters
                • [required] (object) options

                  • (string) title Title of modal window

                  • (string) html HTML for the inner content

                  • (string) id DOM id to give the wrapper element

              • Example
                • Clay.UI.createModal( { title: 'Title', html: "<div>Here's some HTML</div>" } )
              updateModal
              Updates a modal window
              • Parameters
                • [required] (object) options

                  • (string) title Title of modal window

                  • (string) html HTML for the inner content

                  • (string) id DOM id to give the wrapper element

              • 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
                • [required] (object) options

                  • (string) title Title of notification

                  • (string) html HTML for the inner content

                  • (truthy) icon Boolean false if no icon, URL to icon if you want to specify one

                  • (string) type We use two values, 'notification'|'achievement' -- the style differs a bit between the two. Classes are set with the type (ex. "clay-" + type)

                  • (string) id DOM id to assign to wrapper (it's assigned as "clay-" + type + "-" + id). Defaults to 'notification'

                  • (int) delay Notification will be closed after delay ms. Set to 0 to not close at all

              • 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

                • [optional] (function) callback Called when user data is saved

                  • (object) response Contains response data

              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

                • [optional] (function) callback Called when user data is received from server

                  • (object) response Contains response data

              fetchItems
              Grabs all the items this player has in your game
              • Parameters
                • [required] (function) callback

                  • (array) items An array of item ids they have

              grantItem
              Grants the user an item (created in the developer dashboard for your game)
              • Parameters
                • [optional] (object) options

                  • (int) id The item's id (given to you after creating it)

                  • (int) quantity How many of the item you want to give

                • [optional] (function) callback Called when item is granted

                  • (array) response An object with the following properties

                    • (int) id The item's id

                    • (int) quantity How many were given

              removeItem
              Removes an item from the player's inventory
              • Parameters
                • [optional] (object) options

                  • (int) id The item's id (given to you after creating it)

                  • (int) quantity How many of the item you want to remove - pass 'all' to remove all of this item

                • [optional] (function) callback Called when item is removed

                  • (array) response An object with the following properties

                    • (int) id The item's id

                    • (int) quantity How many were removed

              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
                • [optional] (function) callback Called when either purchase has successfully gone through, or if there was an error/canceled process

                  • (object) response

                    • (bool) success True if the user went through the whole process without generating an error

                    • (truthy) error Boolean false if no error, String error message if error

                    • (string) status Info about the payments current status (ex. pending) - this still needs to be normalized on our end. Give us a nudge if we haven't done it yet

                    • (bool) completed Boolean if the payment was approved right away or not

                    • (array) itemIds Array of Integers: The items they ended up purchasing - this could be different than the items you pass since they can optionally remove items

              hasInstalled
              • Return
                • (boolean) installed If the user has "installed" (or purchased if it's not a free game) the game or not

              onUserReady
              Called when the user is logged in (and we have a name for them)
              • Parameters
                • [optional] (function) callback Called when the user has logged in (or entered their name)

                  • (object) response

                    • (string) identifier A unique identifier associated with the user

              login
              Manually triggers the flow for a user to login, signup, or enter their name within the modal window
              • Parameters
                • [optional] (object) options

                  • (string) id Specify if you do not want to use the standard Clay.io UI. Pass the DOM element ID you want the login box to go in

                • [optional] (function) callback Called when either the login was successful, or if there was an error/canceled process

                  • (object) response

                    • (bool) success True if the user logged in successfully

                    • (truthy) error Boolean false if no error, String error message if error

                • [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
                • [optional] (function) callback Called when either the login was successful, or if there was an error/canceled process

                  • (object) response

                    • (bool) success True if the user signed up in successfully

                    • (truthy) error Boolean false if no error, String error message if error

              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
                • [required] (function) callback Called immediately if the user is logged in, or where they login otherwise

                • [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!

              1369158636