[SOLVED]: Automatic turn and interface locking
Posted: 27 June 2020, 18:06
I have a preference in my game that allows the player to have a card picked for them automatically
This feature works if the state is multiplayeraction but I seem to be coming across a race condition of some kind if the action is activePlayer, because sometimes it works and sometimes it does not
My EnterState looks like
As stated the cutDeal seems to always work
The cutCard state though when it calls onDeckSelect. onDeckSelect does a checkAction('cutCard') and fails because the this.interface_locked_by_id still has a guid. I checked it that possible action is in the array, and it is not because the player is not the active player.
The line that fails in ly_studio.js
So overall my question is why is the interacted locked? note if the page is refreshed then the same code runs, since the state has not changed, and everything works on reload
The error message I get is
Please wait, an action is already in progress
(Generated by: checkAction/cutCard)
This feature works if the state is multiplayeraction but I seem to be coming across a race condition of some kind if the action is activePlayer, because sometimes it works and sometimes it does not
My EnterState looks like
Code: Select all
onEnteringState: function (stateName, args) {
switch (stateName) {
case 'cutCard':
if (this.player_id == this.getActivePlayerId()) {
if ($('preference_control_130').value === "1") {
// only auto cut if auto cut is true and if it is cut card then make sure only the active player can auto cut
var randomCard = Math.floor(Math.random() * 52)+1;
this.onDeckSelect(null, randomCard);
return;
}
}
this.hideElement('#cutCard')
this.showElement('#deckContainer');
this.spreadDeck('fullDeck', 40);
break;
case 'cutDeal':
if ($('preference_control_130').value === "0") {
this.hideElement('#cutCard')
this.showElement('#deckContainer');
this.spreadDeck('fullDeck', 52);
} else {
// only auto cut if auto cut is true and if it is cut card then make sure only the active player can auto cut
var randomCard = Math.floor(Math.random() * 40)+1;
this.onDeckSelect(null, randomCard);
}
break;
}
},
The cutCard state though when it calls onDeckSelect. onDeckSelect does a checkAction('cutCard') and fails because the this.interface_locked_by_id still has a guid. I checked it that possible action is in the array, and it is not because the player is not the active player.
The line that fails in ly_studio.js
Code: Select all
checkLock: function(_d8e) {
if (this.isInterfaceLocked()) {
if (typeof _d8e == "undefined") {
this.showMessage(__("lang_mainsite", "Please wait, an action is already in progress"), "error");
}
return false;
}
return true;
},
checkAction: function(_d8f, _d90) {
if (!this.checkLock(_d90)) {
if (typeof _d90 == "undefined" && this.developermode) {
this.showMessage("(Generated by: checkAction/" + _d8f + ")", "error");
}
return false;
}
Code: Select all
onDeckSelect: function (control_name, item_id) {
var action = this.gamedatas.gamestate.name;
if (item_id > 0) {
if (this.checkAction(action)) {
this.ajaxcall("/" + this.game_name + "/" + this.game_name + "/" + action + ".html",
{
card: item_id,
lock: true
}, this, function (result) { }, function (is_error) {}
);
}
this.deck.unselectAll();
}
},
The error message I get is
Please wait, an action is already in progress
(Generated by: checkAction/cutCard)