[messages] [Module Design] Randomizing game piece images.

DrNostromo drnostromo at drnostromo.com
Fri Oct 18 07:54:23 MST 2013

Sounds like what you want to use is a Layer trait controlled by a
Dynamic Property that is assigned randomly.

Ok, I'm assuming you're going to use 3 images.

Add a Dynamic Property to your piece. Give it a name like - ImageCode.
Make it numeric with a range from 1 to 3.
Key Command - SetImageCode
Type - Set value directly
New value - $D3_result$

Add another Dynamic Property to your piece with the name - ImageSet.
Make it numeric with a range from 0 to 1 with a starting value of 0.
KeyCommand - ImageLock
Type - Set value directly
New value - 1

Add a Layer trait
Check Always active
Uncheck Loop through levels
Check Level follows expression value
Follow Expression - ImageCode
Add your images as layers 1, 2, 3

Add a Global Hotkey trait
Keyboard Command - GetD3Roll
Global Hotkey - RollD3

Add a Trigger Action trait
Trigger when properties match - ImageSet = 0
Keyboard command - MapSwitch
Perform these keystrokes

In the Map Window properties at the bottom, you find:
Key Command to apply to all units ending movement on this map -

Add a Dice Button to your main Vassal tree
Name - D3
Leave Button Text, Tooltip Text, and Button Icon blank
Number of dice - 1
Number of side per die - 3
Add to each die - 0
Add to overall total - 0
Check Report Total
Hotkey - RollD3
Uncheck - Prompt for values

Now, when a piece is moved to the map, the key command MapSwitch will be
triggered. Your trigger action trait will roll a D3 and set that value
as the ImageCode. Your layer trait will then display the image assigned
to that code. It will also set the ImageSet variable to 1 so that the
image won't change every time you move the piece as trigger action will
only work if ImageSet is set to 0.

Does that work?

Read this topic online here:

More information about the messages mailing list