I want to add the $PlayerName$ unique to each Player. I have a toolbar icons for Players 1-6. I would like to use the actual players Name and not Player 1… If I put $PlayerName$ all 6 players slots have the Name of the person on that computer.
(post deleted by author)
You need a set of Global Properties to store the name of the player for each side, and then a Startup Global Key Command to set the name of the player for the current side (this will run as each player joins the game).
The code to do this is…somewhere…in the Terraforming Mars modules, but I couldn’t actually find it on a cursory inspection. I’ll take another look when I have more time.
Edit: On further review of Terraforming Mars, it actually doesn’t store the player names; it stores which player color is in which “seat”, with seat1
being the first player to join the game, and so on (the game never needs to look up the names of other players, so it doesn’t bother storing that info).
Unfortunately, it doesn’t do this automatically, instead it requires the players to click on a button to “officially” join the game before the game actually starts, and the GP is set then.
This is needlessly complicated, and I wouldn’t recommend actually copying it.
You would need your Startup GKC to call a set of trigger actions (one for each possible player side); each trigger action would have a condition that only triggered if {PlayerSide == "<name of a player side>"}
, substituting your actual player sides for <name of a player side>
, and in turn would need to call a Set Global Property trait that sets the GP for that side to the current {PlayerName}
(or $PlayerName$
, if you prefer) (or, as Benkyo suggested, use PlayerId
instead, which you can customize in your Global Options).
These trigger actions need to be on a piece already fixed on the board in an At-start Stack. It could be a piece you’re already using for something else, or even a piece with no image at all so it can’t otherwise been seen or interacted with.
My buddy has done this on a few modules. He keys off the “At Start of Fresh Game or Player Join/Side-Change”. This works for the first player to join. For the remaining players the workaround is to retire and re-join. More details in this post: Startup GKC not working on Player Join. I’ve implemented a new Startup Global Key Command that only fires on player join/side-change. It’s in the queue for inclusion into Vassal. That would make this feature work seamlessly.
You do need a set of Global Properties to store the names. These are the button text. Base these Global Properties off of the player sides. As an example, if you have Red, Blue and Green sides, make your properties RedName, BlueName and GreenName. Consistent naming simplifies the setting of player names by avoiding conditionals.
Setup the Startup Global Key Command with a Global Key Command (i.e. not Hot key).
Add a single piece to an At-Start Stack. The single piece has a Trigger Action and Set Global Property. The Trigger Action filters out player retirements to observer. Trigger when {PlayerSide!=“”}. The trigger invokes the Set Global Property, of which the name is {PlayerSide+“Name”}. Thus circling back to the naming of the Global properties (i.e. if PlayerSide is Red, this sets RedName). For the key command, the type is “set value directly” and the Prompt is {PlayerName}.
Without getting into a lot of details that is basically the gist of it. If you don’t like the workaround, the players will have to manually update by clicking on some button. This mostly repeats what has already been posted with a variation on the trigger action.