Page 1 of 1

[SOLVED] notif.args and undefined

Posted: 21 April 2021, 00:14
by Badguizmo
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 :

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
            )
and another one with my value :

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
            )
        );
In JS :

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);
            }
        }, 
My problem is that my logs show that "notif.args.turnOne" is 'undefined' but the first "if" test is still getting in :

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
How can it be possible ? IMAO the test "if (notif.args.turnOne != 'undefined')" should result on "false" :? :?

Did I miss something ? :o

Re: notif.args and undefined

Posted: 21 April 2021, 01:22
by Benoit314
I think you forgot the word typeof ;)

Code: Select all

if (typeof notif.args.turnOne !== 'undefined')

Re: notif.args and undefined

Posted: 21 April 2021, 11:15
by Badguizmo
Mouarf !!
Good point.
Will implement that tonight 👍👍

Re: [SOLVED] notif.args and undefined

Posted: 21 April 2021, 20:47
by Badguizmo
Hello.

Working ;)

Thanks :D