[SOLVED] notif.args and undefined

Game development with Board Game Arena Studio
Post Reply
User avatar
Badguizmo
Posts: 76
Joined: 11 October 2020, 14:27

[SOLVED] notif.args and undefined

Post 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
Last edited by Badguizmo on 21 April 2021, 20:47, edited 1 time in total.
Official BGA developper newb :oops:
User avatar
Benoit314
Posts: 82
Joined: 02 April 2020, 22:12

Re: notif.args and undefined

Post by Benoit314 »

I think you forgot the word typeof ;)

Code: Select all

if (typeof notif.args.turnOne !== 'undefined')
User avatar
Badguizmo
Posts: 76
Joined: 11 October 2020, 14:27

Re: notif.args and undefined

Post by Badguizmo »

Mouarf !!
Good point.
Will implement that tonight 👍👍
Official BGA developper newb :oops:
User avatar
Badguizmo
Posts: 76
Joined: 11 October 2020, 14:27

Re: [SOLVED] notif.args and undefined

Post by Badguizmo »

Hello.

Working ;)

Thanks :D
Official BGA developper newb :oops:
Post Reply

Return to “Developers”