Action Buttons

Game development with Board Game Arena Studio
Post Reply
User avatar
apollo1001
Posts: 191
Joined: 21 July 2015, 10:41

Action Buttons

Post by apollo1001 »

Sorry, another (more serious) problem I am having with action buttons.

I have set up some action buttons, but when they display on the screen they all appear to have the same div id ($12_1). This is then causing issues in the onCubeClick event. Has anyone else experienced anything like this, or can see my silly mistake?

Thanks, Apollo.

Code: Select all

            case 'initialCubeSelection':
                   
                        for ( var id=1; id<=6; id++ ) {
                            var cube = '<div class="cube cube' + id + '" style="display: inline-block;"></div>';
                            var currentChoice = (args.step == 2)? cube + cube : cube;
                            this.addActionButton( 'cubeButton_' + id, _(currentChoice), 'onCubeClick' );
                        }
                    
                   break;
User avatar
Quinarbre
Posts: 140
Joined: 15 December 2013, 23:26

Re: Action Buttons

Post by Quinarbre »

Hi,

This code seems fine, maybe you should post the code for onCubeClick in order to see what's going wrong.
onCubeClick should have an argument evt, and then to get the id of your button, you use evt.currentTarget.id

Just a small nitpick about your code : it would probably be cleaner to replace

Code: Select all

var cube = '<div class="cube cube' + id + '" style="display: inline-block;"></div>';
with a suitable this.format_block in order to separate js code from html.
User avatar
apollo1001
Posts: 191
Joined: 21 July 2015, 10:41

Re: Action Buttons

Post by apollo1001 »

Thank you for the response. It is basically the same code I used for Keyflower so I was fairly sure there was no problem with it but wanted a second opinion before I suggested it was a bug in the framework...

It looks like the action button id's are not being passed through to the buttons correctly as they are all currently assigned 'id=$12_1' for my project.
User avatar
apollo1001
Posts: 191
Joined: 21 July 2015, 10:41

Re: Action Buttons

Post by apollo1001 »

Okay, so I have finally decided to strip this back to nothing and figure out what on earth is causing the problem.

In case anyone else has a similar issue, it seems that {id} is a reserved template block variable name and will overwrite (or mess up) any action button ids. You can fix by simply using {something_id}, {else_id} etc..

I will attempt to add a warning to the studio doc so nobody else wastes months with this bug.
Post Reply

Return to “Developers”