The HTTP Event (Game Maker Studio):
If you don't understand how this event works you can't use Game Jolt api for this engine properly. Only one way of getting data from the server is HTTP event. It will better if you make this example by using codes below then read start reading this topic.
First of all you have to call a http web request. And have to put the request id on a variable. And you will get result in the HTTP event.
Suppose, when I will press Enter it will call a web request and put the id on a variable.
http_web_req = gj_datastore_get_global("version");
This above code will request for data from global data storage of your game. "version" is the key name.
After making this request you will get result on HTTP event after few times depends on your internet speed.
First, you have to check if the request called. It will call after pressing Enter. Check this by gj_result_id function. Then, have to check if internet connection is okay or requested key exists by function gj_result_status.
If you passed this two statements then you are ready for getting data. The fuction gj_result_data_field will give you data. This function needs a parameter. That is "data". But this parameter is different for different result. Read the document for learn more about parameters.
Now, clear results using gj_result_clear. If you run the game it will show you a messy error message. Just avoid it and listen to me...
HTTP event is like Step event. It check for request in every step (but execute codes once per call). It will check the variable http_web_req because you set the code for checking request. But this variable didn't declare. And this is the error.
Declare it with a value in create event. Recommended value is -1. And it will work now.
Example:
// Create Event:
{
http_web_req = -1;
}
// Game Start:
{
gj_init("xxxx","xxxx");
}
// Pressed Enter Event:
{
http_web_req = gj_datastore_get_global("version");
}
// HTTP Event:
{
if gj_result_id() == http_web_req
{
if gj_result_status() == 1
{
data = gj_result_data_field("data");
}
else
{
data = gj_result_error();
}
show_message(data);
gj_result_clear();
}
}
This post is editable. My English is weird. Sorry for that.