My game is fucked, because it relies solely on one function that is used everywhere and that function is now deprecated.
I don't understand how to make it work asynchronously.
Basically my function is Ajax but synchronous:
Such that I can use this function like so:
if (variable from web) == 1, do this
if (variable from web) == true, do that
Set (variable on web) to 7
Now I can do the third asynchronously, that's fine. But the first two require a response immediately, and I don't want or need the game to continue in that time.
For example, game switches is replaced with this function, so when a switch is used I do something like this (but with error handling and such):
conditonal branch: script: {
}
Now that they're saying is that I have to handle this asynchronously instead. Now that doesn't make sense in the context of a conditonal branch.
Say I have a chest. I want to find out if the chest has been opened, so I ask the server (get_switch(1)). I don't want or need the script to continue processing until the response comes through, because I need the value for the rest of the script to make any kind of sense.
But I can't do this synchronously any more.
I don't even understand how this is supposed to work. I guess the answer is it doesn't?
Isn't this going to kill a lot of online games?
I don't understand how to make it work asynchronously.
Basically my function is Ajax but synchronous:
Code:
ajaxRequest = function(param) {
var retrievedData = "";
var get_params = param;
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
retrievedData = xhttp.responseText;
}
}
xhttp.open("GET", "http://website.web/a.php" + "?" + get_params + "&rand=" + Math.random(), true);
xhttp.send();
return retrievedData;
};
Such that I can use this function like so:
if (variable from web) == 1, do this
if (variable from web) == true, do that
Set (variable on web) to 7
Now I can do the third asynchronously, that's fine. But the first two require a response immediately, and I don't want or need the game to continue in that time.
For example, game switches is replaced with this function, so when a switch is used I do something like this (but with error handling and such):
Code:
get_switch = function(t, variable) {
$return = ajaxRequest("a=gs&t=" + t + "&i=" + variable);
return $return;
}
conditonal branch: script: {
get_switch(1);
}
Now that they're saying is that I have to handle this asynchronously instead. Now that doesn't make sense in the context of a conditonal branch.
Say I have a chest. I want to find out if the chest has been opened, so I ask the server (get_switch(1)). I don't want or need the script to continue processing until the response comes through, because I need the value for the rest of the script to make any kind of sense.
But I can't do this synchronously any more.
I don't even understand how this is supposed to work. I guess the answer is it doesn't?
Isn't this going to kill a lot of online games?