Session – Giavapps Game Jolt API

 

About Session Functions

 

For more info about Session functions please visit the following link: http://gamejolt.com/api/doc/game/sessions

 

Session Functions

 

gj_session_open() Opens a game session for a particular user. Allows you to tell Game Jolt that a user is playing your game. You must ping the session with gj_session_ping() function to keep it active and you must close it with gj_session_close() function when you’re done with it. Note that you can only have one open session at a time. If you try to open a new session while one is running, the system will close out your current one before opening a new one. Please note that this function also sets the default alarm for session ping (see gj_alarm_id and gj_alarm_time local variables in the Initialization And Deinitialization paragraph). This function returns the id of the HTTP request. For more info: http://gamejolt.com/api/doc/game/sessions/open

 

gj_session_ping(double status) Pings an open session to tell the system that it’s still active. If the session hasn’t been pinged within 120 seconds, the system will close the session and you will have to open another one. It’s recommended that you ping every 30 seconds or so to keep the system from cleaning up your session. You can also let the system know whether the player is in an “active” or “idle” state within your game through this call. Please note that this function also resets the default alarm for session ping (see gj_alarm_id and gj_alarm_time local variables in the Initialization And Deinitialization paragraph). This function returns the id of the HTTP request. For more info: http://gamejolt.com/api/doc/game/sessions/ping/

double status: sets the idle (false) or active (true) status.

 

gj_session_close() Closes the active session. Please note that this function also stops the default alarm for session ping (see gj_session_alarm and gj_session_time local variables in the Initialization And Deinitialization paragraph).This function returns the id of the HTTP request. For more info: http://gamejolt.com/api/doc/game/sessions/close/

 

gj_session_alarm(double alarm_id, double alarm_time) You can use this function to customize the id and time of the Alarm used for pinging an open Session. Please note that this function also stores the alarm_id and alarm_time values into gj_alarm_id and gj_alarm_time local variables.

double alarm_id: sets the id of the Alarm.

double alarm_time: sets the time of the Alarm (in steps).

 

Code Examples

 

Running A Session

 

Create Event

 

gj_init("game_id","private_key");//Initializes Giavapps Game Jolt API
request_user_auth = gj_user_auth("username","user_token");//Authenticates the user
request_session_open = –1;//Request for opening a new session
request_session_ping = –1;//Request for pinging an open session

 

Game End Event

 

gj_deinit();//Deinitializes Giavapps Game Jolt API

 

Async – HTTP Event

 

if(gj_http_status() != 0){exit;}//Checks if the status is complete

gj_http_result();//Retrieves result data for gj_result_* functions

if(gj_http_id() == request_user_auth)//Checks if the id is equal to the http request id
{

if(gj_result_success())
{
show_debug_message("THE USER’S CREDENTIALS ARE VALID!");
request_session_open = gj_session_open();//Opens a new session for the user
}
else
{
show_debug_message("THE USER’S CREDENTIALS ARE INVALID!");
}

}
else if(gj_http_id() == request_session_open)//Checks if the id is equal to the http request id
{

if(gj_result_success())
{
show_debug_message("SESSION IS OPEN!");
}
else
{
show_debug_message("SESSION IS NOT OPEN!");
}

}
else if(gj_http_id() == request_session_ping)//Checks if the id is equal to the http request id
{

if(gj_result_success())
{
show_debug_message("SESSION HAS BEEN PINGED!");
}
else
{
show_debug_message("SESSION HAS NOT BEEN PINGED!");
}

}

 

Alarm 0 Event

 

request_session_ping = gj_session_ping(1);//Pings the open session to tell the system that it’s still active.

 

I am Luigi Piscopo, also known as DJ GiDeejay / Producer / Remixer in the music world. I am a Producer with a lot of experience in photo editing, video editing, audio editing, graphic design, web design, programming and promotion.

Comments are closed.