How can I determine which action button was pressed?

Game development with Board Game Arena Studio
Post Reply
User avatar
Brederic
Posts: 26
Joined: 29 January 2013, 00:06

How can I determine which action button was pressed?

Post by Brederic »

in onUpdateActionButtons:
...
case 'chooseRandomObject':
this.addActionButton( 'chooseRandomObject_button1', _('1'), 'onChooseRandomObject' );
this.addActionButton( 'chooseRandomObject_button2', _('2'), 'onChooseRandomObject' );
this.addActionButton( 'chooseRandomObject_button3', _('3'), 'onChooseRandomObject' );
this.addActionButton( 'chooseRandomObject_button4', _('4'), 'onChooseRandomObject' );
break;

in onChooseRandomObject()
// How do I determine which action button was pressed?


Thanks!
Brent
User avatar
oulalalala
Posts: 3
Joined: 24 December 2012, 17:25

Re: How can I determine which action button was pressed?

Post by oulalalala »

you split the event,
here's an example you can adapt to your code: (nb, you don't need to put $ , but i like :) )
here, with $action='ATTACK'
$subloc is like '123_145'
$displ is the message to display on action.

Code: Select all

     [...]
    this.addActionButton( 'button_'+$subloc+'_'+$action, _($displ+$subloc), 'on'+$action+'Button');
     [...]
        onATTACKButton:function (evt)
        {
            console.log('onATTACKButton');
            dojo.stopEvent( evt );
            var array = evt.currentTarget.id.split('_');
            $subloc=array[1]+'_'+array[2];
            
            if( this.checkAction( 'attackaction' ) )    // Check that this action is possible at this moment
            {
                 this.ajaxcall( "/yourgame/yourgame/onAttack.html", { lock: true, subloc: $subloc}, 
                             this, function( result ) {
                                
                                // What to do after the server call if it succeeded
                                // (most of the time: nothing)
                                
                             }, function( is_error) {

                                // What to do after the server call in anyway (success or failure)
                                // (most of the time: nothing)

                             } );
            }
        },
Last edited by oulalalala on 29 November 2015, 14:52, edited 1 time in total.
User avatar
Brederic
Posts: 26
Joined: 29 January 2013, 00:06

Re: How can I determine which action button was pressed?

Post by Brederic »

That's great, thanks!
Post Reply

Return to “Developers”