thatbrod

GJAPI 2.0 Cheat Sheet

Nov 11th, 2012
551
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*************************************************************************
  2. **                   Game Jolt API for Game Maker 8.0                   **
  3. **************************************************************************
  4. **    - Last Update: 13 Nov, 2012
  5. **    - Author contact: [email protected]
  6. **    - http://gamejolt.com/developers/achievements-new/
  7. **************************************************************************
  8. **
  9. **  This is an instruction set for how to use the GJ API.
  10. **  Do not run this script, you'll just get a ton of errors.
  11. **
  12. **  If you fully understand how to use the GJ scripts, you may delete this
  13. **  script; It serves no purpose other than to help you out.
  14. **
  15. **  IMPORTANT NOTE:
  16. **      You shouldn't edit or remove any of the scripts to begin with, but
  17. **  pay SPECIAL attention to scripts tagged with:
  18. **      // FRAMEWORK SCRIPT. DO NOT MODIFY.
  19. **
  20. **  NOTES:
  21. **    - To quickly find a script's instructions, click on the magnifying
  22. **  glass that's right by the script name's input field and search for a
  23. **  name!
  24. **    - Before this script will work, you must install the Http Dll 2.3
  25. **  extension that is included in the zip you found this example in.
  26. *************************************************************************/
  27.  
  28.     GJ_init();
  29. /*  Usage:      GJ_init()
  30. **  Returns:  - Nothing
  31. **************************************************************************
  32. ** THIS IS THE MOST IMPORTANT SCRIPT. Make sure this script is run as
  33. ** early as possible, and don't try to call any other API scripts before
  34. ** this one is run!
  35. **
  36. ** THERE ARE ALSO IMPORTANT VARIABLES YOU NEED TO MODIFY IN THIS SCRIPT.
  37. ** Make sure you look inside and change what's neccesary!
  38. */
  39.  
  40.     GJ_getStatus();
  41. /*  Usage:      GJ_getStatus(handleID)
  42. **  Returns:
  43. **          _GJSTATUS_SUCCESS   This means that whatever download was
  44. **                              associated to this status id has finished
  45. **                              with no problems
  46. **          _GJSTATUS_LOADING   This means that the download associated to
  47. **                              this status id is still working
  48. **          _GJSTATUS_ERROR     This means that there was some error,
  49. **                              with the download or with the API's result
  50. **          _GJSTATUS_FREED     This means you have freed this download
  51. **                              from memory.
  52. **************************************************************************
  53. ** This is the SECOND MOST IMPORTANT SCRIPT. You use this with ALL
  54. ** downloads.
  55. **
  56. ** handleID is an ID number that is returned from just about
  57. ** every script that requests information from the API. Make sure you get
  58. ** very familiar with the constants this script returns.
  59. **
  60. ** Before ever using a handleID to get downloaded data, make sure that the
  61. ** download has finished using this script!
  62. */
  63.  
  64. /**************
  65. ** USER DATA **
  66. **************/
  67.     GJ_login();
  68. /*  Usage:      GJ_login(<string> username, <string> token)
  69. **  Returns:  - <bool> success
  70. **************************************************************************
  71. ** If a user isn't already logged in, this will take the given username
  72. ** and token  and attempt to log them in. If successful, all other GJ
  73. ** scripts that require logins will function properly.
  74. **
  75. ** NOTE 1: When GJ_init is run, it will automatically log a user in if
  76. ** their details are available. If you don't want that to happen, set the
  77. ** appropriate variable to false in the GJ_init() script.
  78. **
  79. ** NOTE 2: When this script is successful, the user's details will be
  80. ** stored into a ds_map, stored globally as _GJ_curUser. Use the script
  81. ** GJ_getUserData() with _GJ_curUser as the userMap to get the logged-in
  82. ** user's details. When the user could not be logged in for whatever
  83. ** reason, or you just haven't called the login script yet, _GJ_curUser is
  84. ** set to the special value: noone
  85. */
  86.  
  87.     GJ_logout();
  88. /*  Usage:      GJ_logout(<bool> keepData)
  89. **  Returns:  - Nothing
  90. **************************************************************************
  91. ** Logs a user off if one is logged in. Will also free any data associated
  92. ** with the user that may have been downloaded if keepData is kept as
  93. ** false.
  94. */
  95.  
  96.     GJ_isLogged();
  97. /*  Usage:      GJ_isLogged()
  98. **  Returns:  - <bool> whether or not user is logged in
  99. **************************************************************************
  100. ** Use this to check if a user is logged into your game.
  101. */
  102.  
  103.     GJ_setIdle();
  104. /*  Usage:      GJ_setIdle(<bool> Idle)
  105. **  Returns:  - Nothing
  106. **************************************************************************
  107. ** Sets the state to idle or active. This is used for online sessions and
  108. ** will be seen on the profile page of the logged in user online.
  109. */
  110.  
  111.     GJ_getUser();
  112. /*  Usage:      GJ_getUser(<string> username OR <real> userID)
  113. **  Returns:  - handleID
  114. **************************************************************************
  115. ** Fetches the data of the requested user. Both a username and user ID can
  116. ** be used. The returned handleID can be used with GJ_getUserData.
  117. */
  118.  
  119.     GJ_getUserSet();
  120. /*  Usage:      GJ_getUserSet(<string> idSet)
  121. **  Returns:  - handleID
  122. **************************************************************************
  123. ** Fills in a ds_list with a set of user handle id's
  124. ** The user set will always be ordered in the same way the fed in idSet is
  125. */
  126.  
  127.     GJ_getUserSetList();
  128. /*  Usage:      GJ_getUserSetList(handleID)
  129. **  Returns:  - ds_list index if available
  130. **                  OR
  131. **            - noone (-4) if not available
  132. **************************************************************************
  133. ** When a user set is finally downloaded, its contents will all be stored
  134. ** into a single ds_list structure, each index containing a handleID which
  135. ** will act like any other user's handleID.
  136. ** You get this ds_list using this function.
  137. */
  138.  
  139.     GJ_getUserData();
  140. /*  Usage:      GJ_getUserData(handleID, <string> dataName, <value> default)
  141. **  Returns:  - The data requested from the given userMap
  142. **                  OR
  143. **            - The given default value upon failure
  144. **************************************************************************
  145. ** The dataName's that can be called are all strings, and have the
  146. ** following names and formats:
  147. **
  148. **      id                      The ID of the user.
  149. **
  150. **      type                    Can be "User", "Developer", "Moderator",
  151. **                              or "Administrator".
  152. **
  153. **      username                The user's username.
  154. **
  155. **      avatar_url              The URL of the user's avatar.
  156. **
  157. **      signed_up               How long ago the user signed up.
  158. **
  159. **      last_logged_in          How long ago the user was last logged in.
  160. **                              Will be "Online Now" if the user is
  161. **                              currently online.
  162. **
  163. **      status                  "Active" if the user is still a member on
  164. **                              the site. "Banned" if they've been banned.
  165. **
  166. ** The names below only exist if the user is a developer
  167. **
  168. **      developer_name          The developer's name.
  169. **
  170. **      developer_website       The developer's website, if they put one
  171. **                              in.
  172. **
  173. **      developer_description   The description that the developer put in
  174. **                              for themselves. HTML tags and new lines
  175. **                              have been removed.
  176. **
  177. ** If GJ_fetchImages is set to true, a usable sprite will (eventually) be
  178. ** loaded into the following name.
  179. **
  180. **      avatar_sprite           The downloaded avatar_url as a usable sprite.
  181. **
  182. ** To avoid errors, ALWAYS check if this sprite exists before drawing it!
  183. ** Example:
  184. **      spr = GJ_getUserData(userMap, "avatar_sprite");
  185. **      if (sprite_exists(spr))
  186. **      {
  187. **          draw_sprite(spr, 0, x, y);
  188. **      }
  189. */
  190.  
  191.     GJ_freeUser();
  192. /*  Usage       GJ_freeUser(handleID)
  193. **  Returns:  - Nothing
  194. **************************************************************************
  195. ** Frees all the memory associated with the given user's handleID. Useful
  196. ** for reloading trophies after a user logs out. If you don't free the
  197. ** trophies after you're done with them and load in too many, you'll end
  198. ** up making a memory leak and getting lag or other such serious problems.
  199. */
  200.  
  201.     GJ_freeUserSet();
  202. /*  Usage       GJ_freeTrophySet(handleID)
  203. **  Returns:  - Nothing
  204. **************************************************************************
  205. ** Frees all the memory associated with the given user set's handleID.
  206. */
  207.  
  208.  
  209. /*************
  210. ** TROPHIES **
  211. *************/
  212.     GJ_addTrophy();
  213. /*  Usage:      GJ_addTrophy(<real> trophyID)
  214. **  Returns:  - handleID
  215. **************************************************************************
  216. ** This adds the given trophy to the logged-in user's achieved trophy
  217. ** list.
  218. ** You can find the IDs of your game's trophies by visiting:
  219. **
  220. **      Your Dashboard ==> Manage Your Games >> [Your Game] ==> Manage Achievements
  221. **
  222. ** When handleID is used as the argument in GJ_getStatus(), it will return
  223. ** _GJSTATUS_SUCCESS when the trophy has been added and _GJSTATUS_ERROR if
  224. ** there was a problem.
  225. */
  226.  
  227.     GJ_getTrophy();
  228. /*  Usage:      GJ_getTrophy(<real> trophyID)
  229. **  Returns:  - handleID
  230. **************************************************************************
  231. ** Fetches the trophy data with the given ID. To find trophy ID's, visit:
  232. **
  233. **      Your Dashboard ==> Manage Your Games >> [Your Game] ==> Manage Achievements
  234. **
  235. ** Use the returned trophyMap with GJ_getTrophyData();
  236. */
  237.  
  238.     GJ_getTrophySet();
  239. /*  Usage:      GJ_getTrophySet(<real> setType, <string> idSet)
  240. **  Returns:  - handleID
  241. **************************************************************************
  242. ** Fetches a set of trophies based on the setType. The setType can be:
  243. **
  244. **      0   (All Trophies)      Will fetch all trophies
  245. **
  246. **      1   (Achieved trophies) Will only fetch trophies that the
  247. **                              currently logged in user has achieved
  248. **
  249. **      2   (Missing trophies)  Will only fetch trophies that the
  250. **                              currently logged in user has NOT achieved
  251. **
  252. **      3   (Specific set)      Will fetch the trophies described in the
  253. **                              string idSet, where idSet is a string of
  254. **                              trophy id's separated by commas.
  255. **
  256. ** Note, the returned trophy set will always be ordered in the same way
  257. ** the fed in idSet is, even if you load your set with a different
  258. ** setType!
  259. */
  260.  
  261.     GJ_getTrophySetList();
  262. /*  Usage:      GJ_getTrophySetList(handleID)
  263. **  Returns:  - ds_list index if available
  264. **                  OR
  265. **            - noone (-4) if not available
  266. **************************************************************************
  267. ** When a trophy set is finally downloaded, its contents will all be
  268. ** stored into a single ds_list structure, each index containing a
  269. ** handleID which will act like any other trophy's handleID.
  270. ** You get this ds_list using this function.
  271. */
  272.  
  273.     GJ_getTrophyData();
  274. /*  Usage:      GJ_getTrophyData(handleID, <string> dataName, <value> default)
  275. **  Returns:  - The data requested from the trophy associated with the
  276. **              given handleID
  277. **                  OR
  278. **            - The given default value if it doesn't exist or if the
  279. **              trophy hasn't finished loading.
  280. **************************************************************************
  281. ** The dataName's that can be called are all strings, and have the
  282. ** following names and formats:
  283. **
  284. **      id                      The ID of the trophy.
  285. **
  286. **      title                   The title of the trophy on the site.
  287. **
  288. **      description             The trophy description text.
  289. **
  290. **      difficulty              0 = Bronze, 1 = Silver, 2 = Gold,
  291. **                              3 = Platinum
  292. **
  293. **      image_url               The URL to the trophy's thumbnail.
  294. **
  295. **      has_achieved            A boolean value, true if user has achieved
  296. **                              this trophy, false if not.
  297. **
  298. **      achieved                Returns how long ago the trophy was
  299. **                              achieved by the user, or "false" if they
  300. **                              haven't achieved it yet.
  301. */
  302.  
  303.     GJ_freeTrophy();
  304. /*  Usage       GJ_freeTrophy(handleID)
  305. **  Returns:  - Nothing
  306. **************************************************************************
  307. ** Frees all the memory associated with the given trophy's handleID.
  308. ** Useful for reloading trophies after a user logs out. If you don't free
  309. ** the trophies after you're done with them and load in too many, you'll
  310. ** end up making a memory leak and getting lag or other such serious
  311. ** problems.
  312. */
  313.  
  314.     GJ_freeTrophySet();
  315. /*  Usage       GJ_freeTrophySet(handleID)
  316. **  Returns:  - Nothing
  317. **************************************************************************
  318. ** Frees all the memory associated with the given trophy set's handleID.
  319. */
  320.  
  321.  
  322. /******************************
  323. ** HIGH SCORES/LEADER BOARDS **
  324. ******************************/
  325.     GJ_addScore();
  326. /*  Usage:      GJ_addScore(<real> tableID, <string> scoreDisplay, <real> scoreSort, <string> extraData)
  327. **  Returns   - handleID
  328. **************************************************************************
  329. ** tableID is a unique identifier for specific highscore tables. If you
  330. ** only have one or wish to add the score to your primary table, set
  331. ** tableID to 0. Otherwise, you can find the IDs of your tables by
  332. ** visiting the following:
  333. **
  334. **      Your Dashboard ==> Manage Your Games >> [Your Game] ==> Manage Achievements >> High Scores
  335. **
  336. ** The difference between scoreDisplay and scoreSort is very important.
  337. ** scoreDisplay is a string value associated with the score that is shown
  338. ** instead of a raw numeric value.
  339. ** Example: "234 Jumps".
  340. ** scoreSort is the value that actually determines the position in the
  341. ** high score list, and thus it must be a real value.
  342. ** extraData will not be seen by anything other than the GJ API. You may
  343. ** do whatever you may wish with it.
  344. */
  345.  
  346.     GJ_addGuestScore();
  347. /*  Usage:      GJ_addGuestScore(<real> tableID, <string> guestName, <string> scoreDisplay, <real> scoreSort, <string> extraData)
  348. **  Returns   - handleID
  349. **************************************************************************
  350. ** This allows you to upload the scores of players who either haven't
  351. ** logged in or do not own a GJ account. See GJ_addScore for more details
  352. ** on the arguments.
  353. */
  354.  
  355.     GJ_getUserScores();
  356. /*  Usage       GJ_getUserScores(<real> tableID, <real> limit)
  357. **  Returns   - handleID
  358. **************************************************************************
  359. ** This loads scores that were achieved by the logged-in user
  360. ** specifically.
  361. ** tableID is 0 when you wish to load primary/only have one table, or a
  362. ** specific tableID which can be found by visiting the following:
  363. **
  364. **      Your Dashboard ==> Manage Your Games >> [Your Game] ==> Manage Achievements >> High Scores
  365. **
  366. ** limit is how many scores you wish to fetch. Maximum limit is 100!
  367. ** Use the returned handleID with GJ_get_nScoreData()
  368. **
  369. ** NOTE: Before reloading scores, make sure you clear the previous table
  370. ** by using GJ_freeTableList() !!!
  371. */
  372.  
  373.     GJ_getGlobalScores();
  374. /*  Usage       GJ_getGlobalScores(<real> tableID, <real> limit)
  375. **  Returns   - handleID
  376. **************************************************************************
  377. ** This loads scores achieved by any and all users.
  378. ** tableID is 0 when you wish to load primary/only have one table, or a
  379. ** specific tableID which can be found by visiting the following:
  380. **
  381. **      Your Dashboard ==> Manage Your Games >> [Your Game] ==> Manage Achievements >> High Scores
  382. **
  383. ** limit is how many scores you wish to fetch. Maximum limit is 100!!
  384. ** Use the returned handleID with GJ_get_nScoreData()
  385. **
  386. ** NOTE: Before reloading scores, make sure you clear the previous table
  387. ** by using GJ_freeTableList() !!!
  388. */
  389.  
  390.     GJ_get_nScoreData();
  391. /*  Usage       GJ_get_nScoreData(handleID, <real> n, <string> dataName, <value> default)
  392. **  Returns   - the data value stored at n position of the table
  393. **              associated with the given handleID
  394. **                  OR
  395. **            - default value if there was an error
  396. **************************************************************************
  397. ** the nth position works as follows:
  398. **      (0 = Best score, 1 = 2nd best, 2 = 3rd best, ..., (limit - 1) = limith best)
  399. **
  400. ** The dataName's that can be called are all strings, and have the
  401. ** following names and formats:
  402. **
  403. **      score                   The score string.
  404. **
  405. **      sort                    The score's numerical sort value.
  406. **
  407. **      extra_data              Any extra data associated with the score.
  408. **
  409. **      name                    The name of the scorer.
  410. **
  411. **      user_id                 If this is a user score, this is the user's ID.
  412. **
  413. **      scorer_type             If this is a guest score, 0. If a user score, 1.
  414. **
  415. **      stored                  Returns when the score was logged by the user.
  416. */
  417.  
  418.     GJ_freeScores();
  419. /*  Usage       GJ_freeScores(handleID)
  420. **  Returns:  - Nothing
  421. **************************************************************************
  422. ** Frees all the memory associated with this table list. Very important
  423. ** that you run this if you ever try to reload your scores to prevent any
  424. ** memory leaks!!
  425. */
  426.  
  427. /*****************
  428. ** DATA STORAGE **
  429. ******************
  430. ** Local and global data functions work with the same arguments. The
  431. ** difference is that local requires a user to be logged in, and will
  432. ** upload the requested key/value pairs to their own personal data hub.
  433. **
  434. ** Global values can be accessed without being logged in, and can be
  435. ** fetched and changed by any instance of your game.
  436. *************************************************************************/
  437.  
  438.  
  439. /**********
  440. *  Local  *
  441. **********/
  442.     GJ_getData();
  443. /*  Usage       GJ_getData(<string> key, default)
  444. **  Returns   - Value held at key
  445. **                  OR
  446. **            - default value upon failure
  447. **************************************************************************
  448. */
  449.  
  450.     GJ_loadData();
  451. /*  Usage       GJ_loadData(<string> key)
  452. **  Returns:  - handleID
  453. **************************************************************************
  454. ** Returns data from the Data Store.
  455. **
  456. ** In order to actually access the downloaded key, you need to use the
  457. ** script GJ_getData()
  458. */
  459.  
  460.     GJ_saveData();
  461. /*  Usage       GJ_saveData(<string> key, value)
  462. **  Returns:  - handleID
  463. **************************************************************************
  464. ** Sets data in the Data Store.
  465. */
  466.  
  467.     GJ_remData();
  468. /*  Usage       GJ_remData(<string> key, value)
  469. **  Returns:  - handleID
  470. **************************************************************************
  471. ** Removes data from the Data Store.
  472. */
  473.  
  474.     GJ_editData();
  475. /*  Usage       GJ_editData(<string> key, <string> operation, <real> value)
  476. **  Returns:  - handleID
  477. **************************************************************************
  478. ** Updates data in the Data Store.
  479. **
  480. ** If you are attempting to edit a string, operation must be one of the
  481. ** following:
  482. **
  483. **      append          Given value is put at the end of whatever value is
  484. **                      already online
  485. **
  486. **      prepend         Given value is put at the beginning of whatever
  487. **                      value is already online
  488. **
  489. **  If you are attempting to edit a real, then operation must be one of
  490. **  the following:
  491. **
  492. **      add             Online value has the given value added to it
  493. **
  494. **      subtract        Online value has the given value subtracted from
  495. **                      it
  496. **
  497. **      multiply        Online value is multiplied by the given value
  498. **
  499. **      divide          Online value is divided by the given value
  500. */
  501.  
  502.     GJ_freeData();
  503. /*  Usage       GJ_freeData()
  504. **  Returns:  - Nothing
  505. **************************************************************************
  506. ** Frees all of the downloaded data of the currently logged in user.
  507. */
  508.  
  509. /***********
  510. *  Global  *
  511. ************
  512. **  For instructions on global data storage functions, see their
  513. **  corresponding local version.
  514. **      Example: GJ_getGlobalData() has same instructions as
  515. **      GJ_getData(), but works for global values instead of local ones
  516. *************************************************************************/
  517.     GJ_getGlobalData();
  518.     GJ_loadGlobalData();
  519.     GJ_saveGlobalData();
  520.     GJ_remGlobalData();
  521.     GJ_editGlobalData();
  522.     GJ_freeGlobalData();
Advertisement
Add Comment
Please, Sign In to add comment