button function being called without being clicked (solved)

Game development with Board Game Arena Studio
Post Reply
User avatar
Ballatik
Posts: 2
Joined: 17 April 2020, 02:48

button function being called without being clicked (solved)

Post by Ballatik »

I changed the function name to "onMoveButton" and that seems to have fixed it.

I'm creating two buttons, move and end turn. Clicking on the first one calls the functions for both instead of just the clicked one. I'm sure it's something simple but I've been banging my head against it for way too long.

The button definitions:

Code: Select all

        onUpdateActionButtons: function( stateName, args )
        {
            console.log( 'onUpdateActionButtons: '+stateName );

            if( this.isCurrentPlayerActive() )
            {
                switch( stateName )
                {
                case 'playerTurn':
                    var player = this.gamedatas.players[this.getActivePlayerId ()];
                    if( player.player_AP > 0 )
                    {
                        this.addActionButton( 'move_button', _('Move'), 'onMove' );
                    }
                    this.addActionButton( 'pass_button', _('End Turn'), 'onEndTurn' );
                    break;
                }
            }
        },
The functions called:

Code: Select all

        onEndTurn: function( evt )
        {
            // Stop this event propagation
            dojo.stopEvent( evt );

            // Check for allowed action
            if( this.checkAction( 'pass' ) )
            {
                var player = this.getActivePlayerId ();
                this.ajaxcall( "/unknown/unknown/endTurn.html", { player:player }, this, function( result ) {} );
                // remove any remaining AP
                this.gamedatas.players[player].player_AP = 0;
                this.player_Aps[player].toValue(0);
            }
        },

        onMove: function( evt )
        {
            // Stop this event propagation
            dojo.stopEvent( evt );

            // Check for allowed action
            if( this.checkAction( 'move' ) )
            {
                var player = this.getActivePlayerId ();
                this.ajaxcall( "/unknown/unknown/playerMove.html", { player:player }, this, function( result ) {} );
            }
        },
Last edited by Ballatik on 11 April 2021, 22:16, edited 1 time in total.
User avatar
Quinarbre
Posts: 140
Joined: 15 December 2013, 23:26

Re: button function being called without being clicked

Post by Quinarbre »

A wrong copy-paste in your action.php file maybe?
User avatar
Ballatik
Posts: 2
Joined: 17 April 2020, 02:48

Re: button function being called without being clicked

Post by Ballatik »

It doesn't seem to be. If I remove the onMove function definition everything works fine and the move button just doesn't do anything, but if the function is there it tries to call it no matter which button I push.

Code: Select all

    public function endTurn()
    {
        self::setAjaxMode();
        $player = self::getArg( "player", AT_posint, true );
        $result = $this->game->endTurn( $player );
        self::ajaxResponse( );
    }

    public function playerMove()
    {
        self::setAjaxMode();
        $player = self::getArg( "player", AT_posint, true );
        $result = $this->game->playerMove( $player );
        self::ajaxResponse( );
    }
Post Reply

Return to “Developers”