Hello everyone,
I recently needed to create an animation to make my dice âroll.â Until now, I was only using a âLayer Traitâ with 2 colours to indicate that the die had been rolled. However, this approach works moderately well with a game that has many dice of different colours.
So, I am sharing with you what I did to create this animation.
What I need
Before describing the functionality, here is a list of my requirements:
- I need to have an animation on one or more dice to indicate that they are rolling.
- This animation should only apply to the selected dice.
- This animation can be triggered via a menu button, or through a âMenu Commandâ or âKey Command.â
- The animation should not be too long, and all dice should animate simultaneously (rather than one after the other).
- I would like to have a message in the âChat Logâ displaying the result.
How I represent a dice
Firstly, I represent the different faces of my die with a âLayer Traitâ. I have a âNamed Commandâ to increment (âIncrementâ) and another to randomise (âRandomizeâ). The âLevel nameâ must correspond to the displayed face of the die.
This âLayer Traitâ is in the âDice Redâ prototype definition, which use the âDiceâ prototype definition.
The âDiceâ prototype definition has these traits:
The âBasic Nameâ trait is included here to ensure that the âBasic Nameâ is equal to âDiceâ. This value will be used to create a âPre-select (Fast Match)â in a âGlobal Key Commandâ.
The logic in the pieces
Trigger the action from the dice
There is then a âTrigger Actionâ that provides the user with an option to roll one or more dice. This âTrigger Actionâ will actually initiate these different âKey Commandsâ:
- CheckAndSetGlobalProperty
- DecrementGlobalProperty
- CheckAndStartLoop
CheckAndSetGlobalProperty
âCheckAndSetGlobalPropertyâ is used in the following âTrigger Actionâ, which checks that the âGlobal Propertyâ âNumberDiceSelectedâ is equal to 0. If this is the case, the âKey Commandâ âSetGlobalPropertyâ is triggered.
âSetGlobalPropertyâ is used in the âSet Global Property Traitâ to set the number of selected dice into âNumberDiceSelectedâ.
In summary: if the user selects multiple dice and triggers the âRollâ action, the number of selected dice is placed in âNumberDiceSelectedâ if it is equal to 0 (which means it has not yet been defined).
Note: I would like to remind you that when the user selects multiple pieces and triggers an action on them, Vassal will call that action on each of the selected pieces.
DecrementGlobalProperty
âDecrementGlobalPropertyâ is used to decrement âNumberDiceSelectedâ (as shown in the âSetGlobalPropertyâ image).
CheckAndStartLoop
âCheckAndStartLoopâ serves a similar purpose to âCheckAndSetGlobalPropertyâ. It checks if âNumberDiceSelectedâ is equal to 0; if so, it triggers the âKey Commandâ âStartLoopPieceâ.
âStartLoopPieceâ is simply used to trigger the âGlobal Hotkeyâ âStartLoopâ, which will initiate the animation loop.

Summary
For each piece selected by the user, the âRollâ action will be triggered. The first piece triggered will set âNumberDiceSelectedâ, and then each subsequent piece will decrement âNumberDiceSelectedâ until the last piece triggers the loop.
Construct the message for the âChat Logâ
Each time âRandomizeâ is called, we will concatenate the âGlobal Propertyâ âRollMessageâ with the âPieceNameâ property that corresponds to the value of the die.
The logic in the module
A portion of the logic that enables the animation is defined at the module level.

Loop management
The âAction Buttonâ âRollâ will be triggered when a user presses it or when âStartLoopâ has been initiated. It will first trigger the âHotkeyâ âLoopStartâ (not to be confused with âStartLoopâ), then it will trigger the âHotkeysâ âLoopâ and âSleepâ 10 times (chosen arbitrarily), and finally, it will trigger the âHotkeyâ âLoopEndâ.
LoopStart
âLoopStartâ is used by a âChange-property Toolbar Buttonâ attached to âRollMessageâ to reset âRollMessageâ.
Loop
âLoopâ is used in a âGlobal Key Commandâ that will trigger âIncrementâ on each of the selected dice.
Sleep
âSleepâ is used in a âGlobal Key Commandâ that will trigger the âGlobal Key Commandâ âSleepPieceâ on a piece that has the âBasic Nameâ âSleepPieceâ. This piece is placed outside the play area (-1000, -1000) and contains a âDynamic Propertyâ âSleepPieceâ that holds the âKey Commandâ âSleepPieceâ, allowing the use of the âSleepâ function for 50 ms (chosen arbitrarily).
LoopEnd
âLoopEndâ is used once in a âGlobal Key Commandâ that will trigger âRandomizeâ on each of the selected dice. It is then used a second time in another âGlobal Key Commandâ that will display the result message in the âChat Logâ.
And there you go, it is quite complex, but it works well. Please feel free to let me know if you have any suggestions for improvements!