Page 1 of 1

Handle buttons on actions - best practices

Posted: 18 January 2022, 17:16
by AndreaGot
I started my first small project yesterday, based on the Reversi tutorial, and I would like to apply some changes to the basic gameplay.

I would like to show two buttons after choosing an available cell, asking the player to select the colour of the token they want to place:
What is the common workflow in order to achieve this behaviour?

I see that the buttons need to be added in onUpdateActionButtons() function, but I don't understand how to show them when a specific condition is met (in this case, just after a click on a cell). Colour is just a variable to be set before the onPlayDisc() function since it's the only thing that changes between the two options.

Do I have to setup 2 different states (one for choosing the cell and another for the colour selection) or is it feasible in just one state?

Re: Handle buttons on actions - best practices

Posted: 18 January 2022, 17:28
by robinzig
AndreaGot wrote: 18 January 2022, 17:16 I started my first small project yesterday, based on the Reversi tutorial, and I would like to apply some changes to the basic gameplay.

I would like to show two buttons after choosing an available cell, asking the player to select the colour of the token they want to place:
What is the common workflow in order to achieve this behaviour?

I see that the buttons need to be added in onUpdateActionButtons() function, but I don't understand how to show them when a specific condition is met (in this case, just after a click on a cell). Colour is just a variable to be set before the onPlayDisc() function since it's the only thing that changes between the two options.

Do I have to setup 2 different states (one for choosing the cell and another for the colour selection) or is it feasible in just one state?
Yes you want 2 states, but one can be a "client state" - ie just handled in your Javascript file, without any mention in the states PHP file or the other players being aware of any state change. You will find documentation on client states in the Studio docs/wiki.