java getArg

Game development with Board Game Arena Studio
Post Reply
User avatar
cora89
Posts: 29
Joined: 14 June 2012, 20:29

java getArg

Post by cora89 »

hi,

i want to know in which square my player wants to put his token.
i have defined square_{X} in my .tpl page.
I want to have the X of the square where he wants to play.
Is it possible with getArg or must i find it from the (x,y) mouse position ?

thanks for your help.
Have a nice day.
User avatar
Een
Posts: 3861
Joined: 16 June 2010, 19:52

Re: java getArg

Post by Een »

Hi,

When you set up your squares on the board, you give them an id based on your coordinates.

For example in Reversi :

Code: Select all

<div id="square_{X}_{Y}" class="square" style="left: {LEFT}px; top: {TOP}px;"></div>
Then in your JS you need to attach an onclick event to your squares, so that when clicked, a specific function is called:

Code: Select all

dojo.query( '.square' ).connect( 'onclick', this, 'onPlayDisc' );
Then when the method is called, you get the id of the square through the evt parameter (evt.currentTarget.id), and you can split it to get the coordinates.

Code: Select all

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

            // Get the cliqued square x and y
            // Note: square id format is "square_X_Y"
            var coords = evt.currentTarget.id.split('_');
            var x = coords[1];
            var y = coords[2];

           [...]
        },
Then you can use it as you need (you can find more examples and information in the Reversi tutorial).

Cheers,
Een
User avatar
cora89
Posts: 29
Joined: 14 June 2012, 20:29

Re: java getArg

Post by cora89 »

thx for you help ^^
Post Reply

Return to “Developers”