Page 1 of 1

How can I determine which action button was pressed?

Posted: 29 November 2015, 03:53
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

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

Posted: 29 November 2015, 14:48
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)

                             } );
            }
        },

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

Posted: 29 November 2015, 14:51
by Brederic
That's great, thanks!