[SOLVED] notif.args and undefined
Posted: 21 April 2021, 00:14
Hello everyone.
I have a strange behaviour (well for me it is strange ...)
I am using the same notifyallplayers with a special parameter.
What I want is that if I assign a value, it calls, in JS a method, and if I don't assign, it calls another one.
Here a sample code for notif 1 in php :
and another one with my value :
In JS :
My problem is that my logs show that "notif.args.turnOne" is 'undefined' but the first "if" test is still getting in :
How can it be possible ? IMAO the test "if (notif.args.turnOne != 'undefined')" should result on "false"
Did I miss something ?
I have a strange behaviour (well for me it is strange ...)
I am using the same notifyallplayers with a special parameter.
What I want is that if I assign a value, it calls, in JS a method, and if I don't assign, it calls another one.
Here a sample code for notif 1 in php :
Code: Select all
self::notifyAllPlayers("notifPlayElemental", clienttranslate('${player_name} moved ${cardValue} of "${guildName}" from Rift ${riftIndex} to Rift ${riftIndex}'),
array(
'player_name' => $playerName,
'player_Id' => $playerId,
...
'riftIndex' => $toRiftIndex,
'nbCardsAlreadyInRift' => $nbCardsAlreadyInRift,
'fromRift' => $fromRiftIndex
)Code: Select all
self::notifyAllPlayers("notifPlayElemental", clienttranslate('${player_name}, as second player, automatically played ${cardValue} of "${guildName}" at Rift 3'),
array(
'player_name' => $this->loadPlayersBasicInfos()[$player2id]['player_name'],
'player_Id' => $player2id,
...
'nbCardsAlreadyInRift' => 0,
'turnOne' => true
)
);Code: Select all
notif_PlayElemental( notif )
{
console.log("Dans la notif playElemental");
console.log(notif.args.turnOne);
console.log(typeof(notif.args.turnOne));
console.log(typeof('undefined'));
console.log(notif.args.fromRift);
if (notif.args.turnOne != 'undefined')
{
console.log("Appel playElemental XXX");
console.log(notif.args.turnOne);
console.log((notif.args.turnOne != 'undefined'));
this.playElemental(notif.args.player_Id, notif.args.card_Id, notif.args.location, notif.args.other_player_id, notif.args.GuildId, notif.args.cardValue, notif.args.nbCardsAlreadyInRift,notif.args.turnOne);
}
else
{
console.log("Appel playElemental 2");
this.playElemental(notif.args.player_Id, notif.args.card_Id, notif.args.location, notif.args.other_player_id, notif.args.GuildId, notif.args.cardValue, notif.args.nbCardsAlreadyInRift);
}
}, Code: Select all
Dans la notif playElemental
undefined (from console.log(notif.args.turnOne);)
undefined (from console.log(typeof(notif.args.turnOne));)
string (from console.log(typeof('undefined'));)
3 (from console.log(notif.args.fromRift);)
Appel playElemental XXX
undefined
true
Did I miss something ?