Randomizing the starting setup

Hi there, I am not an advanced mod designer. I have managed to muddle my way through the design process but I have one last hurdle to overcome, and I don’t even know if it is possible.

I have an area control WW2 game where one side has a randomized starting setup. Each region is divided into several zones, and while the starting unit types in the region is fixed, which unit is in which zone is randomized (and hidden/concealed from the opponent).

So far we have been manually placing the starting units in their regions and mixing them up by hand too. But in an ideal world the starting setup would be randomized at game launch.

My question: Is there a way to automate a randomized setup on a map with Vassal?

Thanks so much for taking the time to read. All help appreciated.

I have not done it, but I can think of a way to do it…

Put all the starting units in a “deck” and then have at game startup, develop a script to pull units from the deck, one area at a time… Now if the number per area is ALSO random, this would need to be tweaked…
Area 1 - draw 3 units
Area 2 - draw 1 unit
Area 3 - draw 1 unit
Area 4 - draw 4 units

Have an action button that when pushed initiates the script & hides the units…

Many thanks for your reply, but I am not following. I have only done very basic things with my Vassal mod. How would I develop that script? In what folder would it go?

Number per area is not random, always fixed.


I’ve done this kind of thing a bunch of times with variations. I don’t know how much you know. If I explain something you don’t understand, ask. Some of the concepts may be advanced for you.

Korval is right on principle. You put the pieces in a deck and deal them out from there. Let’s say you have 4 locations on the map where your units will go: 4 in New York, 3 in Denver, 2 in Cleveland, and 1 in Toledo.

  1. Create a prototype for the affected units. In this prototype, add 4 “send-to” commands, one for each target location. For example, one command would be “goToDenver,” and it would say “Main Map” with either the target as a region or as Denver’s (x,y) pixel location. Include this prototype in all the units.

  2. Create a deck. Let’s say we call it “RandomUnits.” Put it somewhere innocuous such as (0,0) or off map. Put all your units to be dispersed to those cities in this deck. Set up the deck as “always shuffle,” and set it up as face up and drawn units are face up. (There is no face down here.)

  3. Next we need to create a script, and this can be done in a number of ways. One way is to create an action button piece in the middle of your map. When you start a new game, it will appear and say something like “Setup” or “Push me.” It would have the following traits:

3a. Basic piece. Here you insert the image you created for the button. It says “Setup.” Or you can leave it blank. In that case, you need to add a text field trait with text = “setup.” (I haven’t tried this alternate approach.)

3b. Add an action button trait. This trait will do the following command: “Distribute”. The checkbox should not be checked.

3c. Add a trigger trait. The command that causes the trigger to run is “Distribute”. It will do 5 other commands, which are 3D, 3e, …

3D-3g Add 4 global key command traits (GKCs). One will be “send4PiecesToDenver”. The global command it will do is “goToDenver”, which is a trait that the units understand. Omit the context menu field. You specify the location as the deck “RandomUnits.” Down below, you say “fixed number of units” and 3, which is how many will go to Denver. Make duplicate traits for the other cities with their number of units.

3h. In the trigger trait above, add the 4 commands (.e.g send4PiecesToDenver) in any order. Then add a 5th command “deleteMe.”

3i. Add a delete trait to your setup piece Leave the menu field blank. Set the command to execute it to “deleteMe.”

Done. When you press the button, it will send the 4 GKCs to the pieces in the deck, which will cause the proper number of units to go to cities. The delete part will delete the button; you don’t need or want it anymore.

Note I use long text strings for my command strings. I do this because it help self-document what’s happening. If I return to the editor later, I don’t want to see a crap-ton of abbreviations.

1 Like

I forgot something. There is a second way to initiate this without a setup button.

At the module level, you can create setup global key command element. You set this up so it runs when you start a new game. It sends a “distribute” command to a piece on the “Main Map” with property type=distributor.

Next edit the button we created above. Remove the button image, any text trait you added, and the action button trait. This piece is now invisible. Add a marker: type=distributor. When you start a new game, a GKC is automatically sent to this setup piece to do its thing.

I call this kind of invisible piece a proxy piece because its sole function to do a job for me. It does not function as a normal piece. I will admt though that sometimes I will embed this proxy logic in some other functioning piece as a side job it does, which no one knows about. Of course, then I don’t want it to delete itself!

1 Like

Many thanks for your detailed and extremely helpful reply. This will definitely get me started! I am sure I will have many questions as I dive into getting this right.