Welcome guest. Please Login or Sign in.

Entry your username and password

DONATE


Help us to keep this site alive

Guide


1. Create a Gamdato Account

Go to Gamdato.com/signin/ and fill in all the fields, accept the terms & conditions and create the account. An activation link will send to your email(It expires in 24h).Once your account was activated, login with your credentials.


2. Registry a Game

If you are logged, go to Gamdato.com/games/, you can registry a game introducing just a name and pressing the "create" button.


When you create a game a control panel will appear with the following content:


» Game information: Information about the game.
» Leaderboards: Panel to manage leaderboards.
» Achievements: Create and manage achivemnts.
» PlayerList: Display a list of the total players




*Important: Save the GAME_ID & GAME_KEY, you will need them to establish the connection between your game and the server.




3. Create a Leaderboard

Go to Leaderboards section, create a new table giving just a name. (You have 3 tables maximum per game).

Once you create a leaderboard, on the settings panel you can edit the following options for your table:


» Order: Downward/Upward scores
» Scores to show: Number of scores to sendback
» Include "0": Acept empty scores
» Extra information titles(3): Titles of extra information you can save besides the name and score of the player(Just for a better visualization on the online dashboard)



Save the settings and close the window, on the leaderboard panel you have information about the properties and submitted scores of your table.


*Important: Save the TABLE_KEY, you will need it to establish the connection between your game and the server.




4. Create an Achievement

Go to Achievements section, press the "create button" to add new achievement. (You have 10 achievements maximum per game).


Name: Name of the new achievement
Description: Description of the new achievement

*Important: Save the "Id" of the achievement, you will need it to establish the connection to the server





1. Install Gamdato Extension

Download gamdato extension: Gamdato.com/downloads, import the extension into your proyect. The downloadable file contains a basic but complete integration of all gamdato services, we recomend to see how it works before using in in your proyect. The next tutorials are going to be based on the example project.

2. Create the Gamdato Controller

Create an object to manage all the gamdato services, it has to be persistent and be created just once when game start. You have to place the following scripts in the Create, Step and Async-HTTP events:

// CREATE EVENT
gmda_setController("GAME-ID","GAME-KEY"); // Game Id & Game Key
gmda_setLeaderboard("TABLE-KEY"); //Table Key

The functions gmda_setController() & gmda_setLeaderboard() establish the connection between your game and the server, fill them with the corresponing credentials.



// STEP EVENT
gmda_Updatefunction(); //Update function

The gmda_Updatefunction() sends requests to server when is necessary, It ensure all is working property.



// ASYNC HTTP EVENT
gmda_HTTPfunction(); //ASYNC HTTP function

The gmda_HTTPfunction() receive the responses from server and update the current information.





3. Create the Request Handlers Scripts

You need to create a set of scripts to manage the responses from server, you do not have to call them the extension does.
*Important: YOU HAVE TO PLACE THEM INTO YOUR PROJECT AND DO NOT CHANGE THE NAMES
You can edit them whatever you want in order to make the necessary adjusts for your project, the scripts are the following:



scrHTTP_player()

// Responses from the server related to player

function scrHTTP_player(response,valueref){

switch(response){

///////////////////// CHANGING NAME //////////////////
case gmd_resp_nameupdated: //Name updated
show_message_async("The name has been changed to: "+string(valueref));
break;
case gmd_resp_namenotavailable: //Name has already been taken
show_message_async("The name "+string(valueref)+" has already been taken");
break;
case gmd_resp_invalidformat_name: //Invalid format(name)
show_message_async("Name: Invalid format");
break;

///////////////// SUBMITTING SCORE ////////////////
case gmd_resp_scoresubmitted: //Score submitted for the first time
show_message_async("Score Submitted!");
break;
case gmd_resp_scoreupdated: //Score updated
show_message_async("Score Updated!");
break;
case gmd_resp_nothigherscore: //Score is not higher than the current one
show_message_async("Submitted score is not higher than the current one...");
break;
case gmd_resp_invalidformat_score: //Invalid format(score or extra fields)
show_message_async("Score: Invalid format");
break;


//////////// EXTRA //////////////
case gmd_resp_newplayer: //Player generated
show_message_async("Player generated!");
break;

default: //Unknown Error
show_message_async("An error has occurred");
break;
}
}





scrHTTP_cloud()

// Manage responses from server related to cloud storage data
//& code generation to recovery the session

function scrHTTP_cloud(response,valueref){

switch(response){
////////////////////////////// LOADING CLOUD DATA /////////////////
case gmd_resp_datareceived: /* DATA RECEIVED */
var gmd_load =json_decode(valueref);
if not(gmd_load="-1"){

show_message_async("Data loaded successfully");

/* Here you can do whatever you want with the data recived(gmd_load - ds_map) */

ds_map_destroy(gmd_load);
}
break;
case gmd_resp_nodata: // No data received
show_message_async("No data received");
break;

////////////////////////////// SAVING CLOUD DATA /////////////////
case gmd_resp_datasaved: //Data saved successfully
show_message_async("Data saved successfully");
break;
case gmd_resp_error_savingdata: //Error when connecting to server
show_message_async("Error to establish connection to server(Saving data)");
break;
case gmd_resp_invalidformat_saving: //Invalid format when saving data
show_message_async("Invalid format(Saving data)");
break;

////////////////////////////// GET RECOVERY CODE /////////////////
case gmd_resp_getcode: //Get recovery code
show_message_async("Your recovery code is: "+string(valueref)); //The code expires in 10min
show_message_async("The code expires in 10min");
break;

case gmd_resp_error_code: //Error when getting a code show_message_async("An error has occurred(recovery code)");
break;

////////////////////////////// RECOVERING SESSION /////////////////
case gmd_resp_sessionloaded: //Session loaded(USING A RECOVERY CODE)
show_message_async("Session loaded!"); //Session recovered
show_message_async("Player name: "+string(valueref));
/*ADVICE: RESTART THE GAME TO PREVENT INFORMATION ERRORS WITH THE PREVIOUS SESSION */
break;
case gmd_resp_invalidcode: //Wrong code
show_message_async("Wrong code..."); //The code is wrong or it expired
break;

/////////////// EXTRA ///////
default: // Unknown error
show_message_async("An error has occurred");
break;
}
}




scrHTTP_game()


// Responses from the server related to game features management

function scrHTTP_game(response,valueref){
switch(response){
/////////////////////////// ACHIEVEMENTS /////////////////////
case gmd_resp_achunlocked: //Achievement got successfully
show_message_async("Achievement got successfully");
break;
case gmd_resp_achalreadygot: //Achievement is already unlocked
show_message_async("Achievement is already unlocked...");
break;
case gmd_resp_invalidach: //Achievement not found
show_message_async("Achievement not found");
break;
case gmd_resp_invalidformat_ach: //Invalid format
show_message_async("Achievement: Invalid format");
break;

/////////////////////////// DAILY REWARDS/INFO /////////////////////
case gmd_resp_rewardgot: //Get reward
show_message_async("You just got: "+valueref+"!");

break;
case gmd_resp_rewardalreadygot: //Achievement is already unlocked
show_message_async("Reward is already got");
break;
case gmd_resp_invalidreward: //Reward not found/not available
show_message_async("Reward not found");
break;
case gmd_resp_invalidformat_rewards: //Invalid format
show_message_async("Reward: Invalid format");
break;

/////////// PERSONALIZED SERVICES //////////////
//You can request personalized functions
//Visit: https://www.gamdato.com/personalize

case gmd_resp_personalize: //Get information(variable)
//HERE PLACE THE APPROPRIATE CODE TO MANAGE THE "PERSONALIZATION SERVICE" INFORMATION
show_message_async("You got some intersting information");
//valueref <- ds_map(DATA)

break;
case gmd_resp_servicenotavailable: //Service is not available
show_message_async("You don't have access to this service...");
break;

/////////// EXTRA //////////
default: //Unknown error
show_message_async("An error has occurred");
break;
}

}




4. Get Player's Name and unique ID

If all the things before are set correctly, when a player open the game, a session file named 'log.dat' will be created saving an unique Id and name generated by the server(This process requires internet connection). When a session is created you can get the player's name and the ID using the gmda_getPlayername() and gmda_getPlayerid() functions respectivily.


Example:

global.playername=gmda_getPlayername(); //Player's nickname
global.player_id=gmda_getPlayerid(); //Unique player ID(DON'T SHOW IT IN THE FINAL VERSION)


*Important: Never show the player's Id when the game is in production



When the session is correctly created/loaded and the connection to server is established, you are able to send requests to server like: changing name, submit score, save/load cloud information and more. All the requests will recive a response that will be manged by the "Request Handlers Scripts" previously explained.

Every time you try to send a request, you have to check if the connection to server is established. Use the gmda_status() function before a request to verify it, it must return "true" or the requests will not be solved correctly.(You will see examples using this function in following tutorials)



5. Changing Player's Name

When a session is created, a player's name is generated automatically. You can change the name using the gmda_setNewname() function, follow the instructions:


syntaxis:gmda_setNewname(NEW_NAME)


» NEW_NAME: New name to set

Example:

// Set a new name
if gmda_status(){
gmda_setNewname(global.newname); //Request changing name to a new one
}

When you try to change the name, the server sends a response that is going to be handled by the scrHTTP_player() function (You have to add this function manually)

Note: Use gmda_status() to verify the connection to the server, it must return "true" or the name will not be changed correctly.






1. Set up a Leaderboard

As we explain in the #2 tutorial, to set up a leaderboard use the gmda_setLeaderboard() function, it has to be next to gmda_setController() function in the create event of the gamdata controller object. You just need to provide the Table-KEY.


Example:

// CREATE EVENT
gmda_setController("GAME-ID","GAME-KEY"); // Game Id & Game Key
gmda_setLeaderboard("TABLE-KEY"); //Table KEY


You can have more than one leaderboard per game, to add another table you just have to use the function gmda_setLeaderboard() and define the new table keys. You can have a maximum number of tables of 3. See the next example for multiple leaderboards:

// CREATE EVENT
gmda_setController("GAME-ID","GAME-KEY"); // Game Id & Game Key
gmda_setLeaderboard("TABLE 1-KEY","TABLE 2-KEY","TABLE 3-KEY"); //Define 3 Leaderboards, using their "TABLE KEY"

/*
Each Table will has a "TABLE NUMBER" to identify them
TABLE 1 - TABLE_NUMBER: 1
TABLE 2 - TABLE_NUMBER: 2
TABLE 3 - TABLE_NUMBER: 3
*/


*Important: When you submit score or request data from a leaderboard, you must specify the table, for that you need the TABLE_NUMBER.

*Note: TABLE_NUMBER: is an id to identify the leaderboards, it corresponds to the order of declaration of each table.




2. Submit a Score

Use gmda_submit() function to submit a score, follow the instructions to send the data correctly:

syntaxis: gmda_submit(TABLE_NUMBER, SCORE,EXTRA DATA 1,EXTRA DATA 2, EXTRA DATA 3)

» TABLE_NUMBER: Number of the leaderboard(Numeric)
» SCORE: Score to submit(Numeric string)
» EXTRA DATA(3): You can save whatever you want(Alphanumeric)(Optional fields)




Example:

// Submit Score and extra information
if gmda_status(){
gmda_submit(TABLE_1,global.xscore,global.information1,global.information2,global.information3);
}


When you submit a score, the server sends a response that is going to be handled by the scrHTTP_player() function (You have to add this function manually)

Note: Use gmda_status() to verify the connection to the server, it must return "true" or the score will not be saved correctly.


Advice: Always save the best score locally, and submit it when the connection to server it is available.





3. Show Leaderboards

Use gmda_getTabledata() function to get the leaderboard information, follow the instructions:
syntaxis: gmda_getTabledata(TYPE, TABLE_NUMBER)


» TYPE: Indicates the type(2) of table to get it's information.(Constant)
    1- gmda_globaltable: Get the top global scores from a specific leaderboard.(Includes extra data fields)
    2- gmda_playertable: Get the best player's score from a specific leaderboard.(Includes extra data fields)
» TABLE_NUMBER: Number of the leaderboard to get the data (Numeric)



Example:

// Get global scores from table 1 and draw the leaderboard
var gettable=gmda_getTabledata(gmda_globaltable,1);
gmda_draw_table(128,256,gettable,1);


The function gmda_getTabledata() returns a ds_map with the table information, following the next structure:

//Table information(ds_map) structure
{
"1": {"name": "Corvus", "score": "100", "d1": "2", "d2": "10", "d3": "Mexico" },
"2": {...},

...

"n": {...}
}


The above ds_map content the top scores information from 1 to n players. Now, If you want to get the score from the row 1, you can try:

var infoplayer = ds_map_find_value(gettable, "1"); // Get row 1 information
var score = ds_map_find_value(infoplayer, "score"); //Get score from row 1


There are many ways to draw the ds_map information, however the downloadable file includes the function gmda_draw_table() (it is not part of the extension) to draw the leaderboard:


gmda_draw_table()

/* Draw Leaderboard */

function gmda_draw_table(xc,yc,table,identifyplayer){

/*
xc - x position
yc - y position
table - table information(ds_map)
identifyplayer - Identify player?, it will color player´s row(Leave it empty if you dont want)
*/

/* Titles */
var titles;
titles[1]="Name: " //Name
titles[2]="Score: " //Score
titles[3]="Level: " //Extra information 1(example);
titles[4]="Kills: " //Extra information 2(example);
titles[5]="Country: " //Extra information 3(example);
var size=ds_map_size(table);
var rowspace=32; //space between rows
var horsize=632; //horizontal lenght
var colortoidentify=c_green; //Color to identify player

draw_set_colour(c_dkgray);
draw_roundrect(xc,yc,xc+horsize,yc+rowspace*11,0);
draw_set_halign(fa_left);
draw_set_valign(fa_center);

if size>0{
for(var i=1;i<=size;i++){
    var infoplayer=ds_map_find_value(table,string(i)); //Get individual player information
      var name=ds_map_find_value(infoplayer,"name");
      var xscore=ds_map_find_value(infoplayer,"score");
      var d1=ds_map_find_value(infoplayer,"d1");
      var d2=ds_map_find_value(infoplayer,"d2");
      var d3=ds_map_find_value(infoplayer,"d3");

      if (name==identifyplayer){
      //Change color if it's the player's row
      draw_set_colour(colortoidentify);
      }else{
      draw_set_colour(c_gray);}
      draw_roundrect(xc+4,yc+rowspace*i,xc+horsize-4,yc+rowspace*i+rowspace-4,0) //Draw Rows
      draw_set_colour(c_white);
      draw_text(xc+10,yc+rowspace*i+16,string(i)+". "+name);
      draw_text(xc+200,yc+rowspace*i+16,xscore);
      draw_text(xc+300,yc+rowspace*i+16,d1);
      draw_text(xc+400,yc+rowspace*i+16,d2);
      draw_text(xc+500,yc+rowspace*i+16,d3);

}}

// Draw titles of leaderboard information
draw_set_colour(c_white);
var inc;
for(var s=0;s < 5;s++){
  if (s==0){inc=10}else{inc=100;}
  draw_text(xc+inc+s*100,yc+22,titles[s+1])
}
}



*Note: If you want to refresh the information use gmda_reloadinfo() function





4. Get Player's Information

There are several functions to get player's information, in the tutorial #2 we have already explain the functions: gmda_getPlayername() and gmda_getPlayerid() to get player's name and ID. When a score is submitted, you can also request information about the player's position on the leaderboard, the best score and "Extra information fields"(saved with the best score). Use the following functions to request that information:

» gmda_getPlayerpos(TABLE_NUMBER): Get Player's global position from an specific leaderboard.
» gmda_getBestscore(TABLE_NUMBER): Get Player's best score from an specific leaderboard.
» gmda_getExtrainfo(id,TABLE_NUMBER): Get Player's "Extra information" from an specific leaderboard. Specify the number of the extra information you request from using "id" parameter.


Example for multiple leaderboards:

// Get player's Information

global.playername=gmda_getPlayername(); //Player's nickname

var numtable=3; // Number of leaderboard connected, example: 3
for(var gmd_i=1;gmd_i<=numtable;gmd_i++){ //Cycle for multiple leaderboars tables(max: 3)
  global.playerpos[gmd_i]=gmda_getPlayerpos(gmd_i); // Player's global position
  global.bestscore[gmd_i]=gmda_getBestscore(gmd_i); //Best score submitted
  global.dat1[gmd_i]=gmda_getExtrainfo(1,gmd_i); //"Extra information 1" saved with the best score
  global.dat2[gmd_i]=gmda_getExtrainfo(2,gmd_i); //"Extra information 2" saved with the best score
  global.dat3[gmd_i]=gmda_getExtrainfo(3,gmd_i); //"Extra information 3" saved with the best score
}

The above example save the player's information into global variables. For player's position, best score and "extra information fields" you can use an array(max-size: 3) to manage the data, where the index corresponds to the TABLE_NUMBER of a leaderboard.






1. SAVE DATA

Use the function gmda_sendgamesave() to send data for cloud saving, you just need to give a ds_map with the information you want , the ds_map will become to json format and be storage on the database. Follow the next example:


syntaxis: gmda_sendgamesave(ds_map)


» ds_map: ds_map with the information to save

Example:

// Create a ds_map with the information to save and send it to the server
if gmda_status(){
var gmd_savemap=ds_map_create(); //create ds_map
ds_map_add(gmd_savemap,"x",string(obj_playertest.x)) //Save the player's x-position
ds_map_add(gmd_savemap,"y",string(obj_playertest.y)) //Save the player's y-position
ds_map_add(gmd_savemap,"money",string(global.money)) //Save the player's money
ds_map_add(gmd_savemap,"Map-id",string(global.mapid)) //Save the current room id
gmda_sendgamesave(gmd_savemap); //Send data to server //Send ds_map to server
ds_map_destroy(gmd_savemap); // destroy ds_map to free space
}

The above example creates a ds_map and save the following information: 'x' and 'y' position, money and room id. You are free to use whatever key's names you want, but you have to consider it when loading data.

When you save data, the server sends a response that is going to be handled by the scrHTTP_cloud() function (You have to add this function manually)

*Important: The ds_map is converted to a json format which the maximum length of characters must be 300, otherwise the information will not be saved.

Note: Use gmda_status() to verify the connection to the server, it must return "true" or the data will not be saved correctly.




2. LOAD DATA

Use the function gmda_loadgamesave() to load data from the server. If the player has already a saving on the database, you will recive a json with same structure you use when saved the information. Follow the next example:


syntaxis: gmda_loadgamesave()


Example:

// Load saving from the server
if gmda_status(){
gmda_loadgamesave(); //Load data
}

When you load data, the server sends a response that is going to be handled by the scrHTTP_cloud() function (You have to add this function manually)

Note: Use gmda_status() to verify the connection to the server, it must return "true" or the data will not be loaded correctly.




The next code is a modification of the function: scrHTTP_cloud() to load the information from the previous example:



scrHTTP_cloud() - modified*

// Manage responses from server related to cloud storage data
//& code generation to recovery the session

function scrHTTP_cloud(response,valueref){
switch(response){
////////////////////////////// LOADING CLOUD DATA /////////////////
case gmd_resp_datareceived: /* DATA RECEIVED */
var gmd_load =json_decode(valueref);
if not(gmd_load="-1"){

show_message_async("Data loaded successfully");

/* Here you can do whatever you want with the data recived(gmd_load - ds_map) */
  if variable_global_exists("save_version"){
  if (ds_map_exists(gmd_load,"version")){
  var get_save_version=(ds_map_find_value(gmd_load,"version"));
  if not(get_save_version=global.save_version){
  show_message_async("Warning: The current version and the version saved are different");
  }}
  if(ds_map_exists(gmd_load,"money")){global.money=real(ds_map_find_value(gmd_load,"money"))}
  if(ds_map_exists(gmd_load,"Map-id")){global.mapid=real(ds_map_find_value(gmd_load,"Map-id"))}
  if(ds_map_exists(gmd_load,"x")){obj_playertest.x=real(ds_map_find_value(gmd_load,"x"))}
  if(ds_map_exists(gmd_load,"y")){obj_playertest.y=real(ds_map_find_value(gmd_load,"y"))}
  }
ds_map_destroy(gmd_load);
}
break;

case gmd_resp_nodata: // No data received
show_message_async("No data received");
break;

////////////////////////////// SAVING CLOUD DATA /////////////////
case gmd_resp_datasaved: //Data saved successfully
show_message_async("Data saved successfully");
break;
case gmd_resp_error_savingdata: //Error when connecting to server
show_message_async("Error to establish connection to server(Saving data)");
break;
case gmd_resp_invalidformat_saving: //Invalid format when saving data
show_message_async("Invalid format(Saving data)");
break;

////////////////////////////// GET RECOVERY CODE /////////////////
case gmd_resp_getcode: //Get recovery code
show_message_async("Your recovery code is: "+string(valueref)); //The code expires in 10min
show_message_async("The code expires in 10min");
break;

case gmd_resp_error_code: //Error when getting a code
show_message_async("An error has occurred(recovery code)");
break;

////////////////////////////// RECOVERING SESSION /////////////////
case gmd_resp_sessionloaded: //Session loaded(USING A RECOVERY CODE)
show_message_async("Session loaded!"); //Session recovered
show_message_async("Player name: "+string(valueref));
/*ADVICE: RESTART THE GAME TO PREVENT INFORMATION ERRORS WITH THE PREVIOUS SESSION */
break;
case gmd_resp_invalidcode: //Wrong code
show_message_async("Wrong code..."); //The code is wrong or it expired
break;

/////////////// EXTRA ///////
default: // Unknown error
show_message_async("An error has occurred");
break;
}
}

In the previous example, we decoded the json recived from server and crate a ds_map("gmd_load") with the data. The ds_map has the same structure of the ds_map saved, so you can get the information using the proper ds_map functions on game maker



Note: Remember destroy the ds_map once you load the information from it, or may consume memory.



3. RECOVERING SESSION



Generate recovery code

You can open the session in other device, using the recovering by code method. It concist in generate an unique alphanumeric code(6 lenght) in the current device, and then entry the code in a new device, where the player will recover the session. You can request the recovery code using the gmda_getRecoverycode() function.


Example:

////////////// Get recovery code //////////////
if gmda_status(){
    gmda_getRecoverycode();
}



When you request for a code, the server sends a response that is going to be handled by the scrHTTP_cloud() function (You have to add this function manually)

Note: Use gmda_status() to verify the connection to the server, it must return "true" or the code request will not be realized correctly.




Recover session by code

Once you generated the recovery code, goto the device where you want to load the session. You can recover the session using the gmda_getSession(code) function, following the next example:

syntaxis: gmda_getSession(code)

» code: recovery code, generated on the older device

Example:

////////////// Recovering session //////////////
if gmda_status(){
    gmda_getSession(global.recovercode); //Recover session using the code;
}


When you try to recover a session by the code, the server sends a response that is going to be handled by the scrHTTP_cloud() function (You have to add this function manually)

Note: Use gmda_status() to verify the connection to the server, it must return "true" or the session will not be loaded correctly.









1. DEFINE ACHIEVEMENTS

Use the function gmda_define_achievement() to set the different achievements of your game, this function must be place in the create event of the gamdat controller objetc after the gmda_setController() and gmda_setLeaderboard() functions. Repeat the function for each achievement of the game, following the next syntaxis:


syntaxis: gmda_define_achievement(name,id,description,value)


Example:


// Create
gmda_setController("Gameexample7w51ozhktgrnWkVHcB9","Mkomm4nwwUtpTNRRC8em7fTKYGL1AasNQgF91Z"); // Game Id & Game Key
gmda_setLeaderboard("P165jRqN3uNR2O8zAsN"); //Table Id

/* Define achievements */
gmda_define_achievement("Grand Lord","jsKT","Destroy all the enemies","1");// achievement 1
gmda_define_achievement("Pig Rider","VOnY","Ride a pig","2");// achievement 2
gmda_define_achievement("Gold fever","H34sjdf34","Get 10,000 gold","3");// achievement 3


» name: Achievement name, is just for visualization purpose
» id: Achievement Id, it is set on the achievement properties on the game panel(web)
» description: Achievement description, is just for visualization purpose
» value: Achievement value, you can use it for whatever you want.




2. SHOW ACHIEVEMENTS

The achievement definition creates a ds_map with all the information, use the gmda_get_achievement_list() function to get the achievement ds_map, which has the following structure:


//Achievements information(ds_map) structure
{
"1": {"name": "Grand Lord", "ide": "jsKT", "descrip": "Destroy all the enemies", "value": "1" },
"2": {...},

...

"n": {...}
}


There are many ways to display the ds_map data, however, the example file contains the function "gmda_draw_achievements"(This function is not part of the extension) to draw a table with the name, description and an small image for all defined achievements:

gmda_draw_achievements(xc, yc)


/* Draw Achievements */
function gmda_draw_achievements(xc,yc){
/*
xc - x position
yc - y position
*/
//Get Achievements ds_map
var table=gmda_get_achievement_list();
//Sprite of the achievements image
var spr_achievements=spr_achievements_images; //Achievements sprite
var rowspace=48; //Row space
var horsize=300; //horizontal lenght

if not(is_undefined(table)){
var size=ds_map_size(table);

//Draw table
draw_set_colour(c_dkgray);
draw_roundrect(xc,yc-4,xc+horsize,yc+rowspace*size,0);

if xsize>0{

  for(var i=0;i < xsize;i++){

    var infoachievement=ds_map_find_value(table,string(i+1));
    //Get achievement information
    var name=ds_map_find_value(infoachievement,"name")
    var descrip=ds_map_find_value(infoachievement,"descrip")
    var img_num=real(ds_map_find_value(infoachievement,"value"));
    var id_ach=ds_map_find_value(infoachievement,"ide");
    var achieved=gmda_check_achievement(id_ach);

    //Change row color if the achievement was got
    if (achieved){draw_set_color(c_green)}else{draw_set_color(c_gray)}
    draw_roundrect(xc+4,yc+rowspace*i,xc+horsize-4,yc+rowspace*i+rowspace-4,0) //Draw Rows

    //Draw information
    draw_sprite(spr_achievements,img_num,xc+24,yc+rowspace*i+10);
    draw_set_colour(c_yellow);
    draw_text(xc+8+60,yc+16+rowspace*i,name)
    draw_set_colour(c_white);
    draw_text(xc+8,yc+rowspace*i+16,string(i+1)+". ");
    draw_text(xc+8+60,yc+36+rowspace*i,descrip)

}}}}



*Important: The above script requires a sprite named "spr_achievements_images" with all the achievement images(32x32 px), the script use the "value" property of the achievement to index an image, that value is set on the achievement definition.

Advice: Modify whatever you want the gmda_get_achievement_list() function to adapt it for your game.





3. GET ACHIEVEMENTS

You can get/unlock achievements using gmda_get_achievement(achievement_id) function, you just have to specify the "achievement id" for the one you want to get.


syntaxis: gmda_get_achievement(achievement_id)


Example:

//When the monster is killed
if gmda_status(){
gmda_get_achievement("FhDa4wQ") //The id of the achievement
}


The above code will get/unlock the achievement with the specified id. When you try to unlock an achievement, the server sends a response that is going to be handled by the scrHTTP_game() function (You have to add this function manually)

Note: Use gmda_status() to verify the connection to the server, it must return "true" or the achievement will not be unlock correctly.

Advice: Always save the proper information to verify if some achievement is already get, and use gmda_get_achievement() again when the connection is establish correctly, you can verify if the achievement is already unlocked using gmda_check_achievement(id) function.






4. ACHIEVEMENT NOTIFICATION(EXTRA)

There are many ways to draw a small notification when an achievement is unlocked, however, the downloadable file contains an example. The first step is to modify the scrHTTP_game() script, when an achievement is got successfully we can create an object("achievement_got_effect") to display an small notification, giving it the achievement id(ach_id=achievement_id).


scrHTTP_game() * Modified

// Responses from the server related to game features management

function scrHTTP_game(response,valueref){
switch(response){
/////////////////////////// ACHIEVEMENTS /////////////////////
case gmd_resp_achunlocked: //Achievement got successfully
show_message_async("Achievement got successfully");
var object_effect=instance_create_depth(room_width-450,room_height-60,depth,achievement_got_effect);
object_effect.ach_id=valueref;
break;
case gmd_resp_achalreadygot: //Achievement is already unlocked
show_message_async("Achievement is already unlocked...");
break;
case gmd_resp_invalidach: //Achievement not found
show_message_async("Achievement not found");
break;
case gmd_resp_invalidformat_ach: //Invalid format
show_message_async("Achievement: Invalid format");
break;

/////////////////////////// DAILY REWARDS/INFO /////////////////////
case gmd_resp_rewardgot: //Get reward
show_message_async("You just got: "+valueref+"!");

break;
case gmd_resp_rewardalreadygot: //Achievement is already unlocked
show_message_async("Reward is already got");
break;
case gmd_resp_invalidreward: //Reward not found/not available
show_message_async("Reward not found");
break;
case gmd_resp_invalidformat_rewards: //Invalid format
show_message_async("Reward: Invalid format");
break;

/////////// PERSONALIZED SERVICES //////////////
//You can request personalized functions
//Visit: https://www.gamdato.com/personalize

case gmd_resp_personalize: //Get information(variable)
//HERE PLACE THE APPROPRIATE CODE TO MANAGE THE "PERSONALIZATION SERVICE" INFORMATION
show_message_async("You got some intersting information");
//valueref <- ds_map(DATA)

break;
case gmd_resp_servicenotavailable: //Service is not available
show_message_async("You don't have access to this service...");
break;

/////////// EXTRA //////////
default: //Unknown error
show_message_async("An error has occurred");
break;
}

}


The variable "ach_id" in the object "achievement_got_effect" contains the achievement id, you can get achievement information using their id with the function: gmda_get_achievement_info(id). Include the following scripts in the object "achievement_got_effect" to draw a notification:

Create Event(object: achievement_got_effect)

//CREATE EVENT - object: achievement_got_effect
alpha=0;
ach_id="";
dir=1;



Draw Event(object: achievement_got_effect)

//DRAW A SMALL NOTIFICATION - DRAW EVENT - object: achievement_got_effect
//Use gmda_get_achievement_info(id) to get achievement information(name,descrip,value..)

// Alpha and y-movement of the notification
alpha+=0.02*dir;
if alpha>4{dir=-1}
if alpha<1{
y-=0.5*dir;
}

if alpha<0{instance_destroy()}
draw_set_alpha(alpha)

draw_set_color(c_green) //Notification color
draw_roundrect(x,y,x+400,y+50,0) //Draw a box
var ach_info=gmda_get_achievement_info(ach_id);//Get achievement information
var ach_name=ds_map_find_value(ach_info,"name"); //Get name
var varach_value = real(ds_map_find_value(ach_info,"value")); //Get value(used for index an image)
draw_sprite(sprite_index,varach_value,x+8,y+8) //Draw achievement image
draw_set_color(c_yellow) //Notification title color
draw_text_transformed(x+48,y+15,"ACHIEVEMENT UNLOCKED:",1,1,0);// Draw notification title
draw_set_color(c_white)//achievement name color
draw_text_transformed(x+48,y+35,ach_name,1,1,0); //Draw name

//Draw a white border
draw_roundrect(x,y,x+400,y+50,1)
draw_roundrect(x,y,x+398,y+52,1)

draw_set_alpha(1)

*Important: The above script requires a sprite named "spr_achievements_images" with all the achievement images(32x32 px), the script use the "value" property of the achievement to index an image, that value is set on the achievement definition.

Advice: Modify whatever you want the above scripts to adapt them for your game.







IMPROVE





gamdato (2021)       -       [email protected]       -       Terms & Conditions