I have a module with a dedicated Attack roll button–it’s just a dice roller button that messages “$PlayerName$ rolls an Attack. Result: $result$.” when clicked.
Players can also trigger the Attack button with a Global Hotkey on a Piece. The Global Hotkey will still return, for example, “Bill rolls an attack. Result: 7.” This is accurate and will serve, but it’s not quite what I’d like to do.
What I’d like it to do, is when the player triggers the Global Hotkey on the piece, include the name of the piece in the message, that is: “Bill rolls an attack with a Battleship. Result: 7.” Then there’s no doubt which piece is actually making the attack.
So for the message, I was assuming I’d be able to use something like “$playername$ rolls an attack with $PieceName$. Result: $result$”
Thing is, $PieceName$ and $BasicName$ don’t show up in the message. They’re both blank, so you get “Bill rolls an attack with. Result: 7.” Neither of these piece properties appears to be passed by the Global Hotkey trait.
Is there another property I should use instead that can be passed along? Or is this just not the way to accomplish what I’m trying to do?
Exactly which component is generating the message?
I don’t understand what you mean by a property being ‘passed’ by the Global Hotkey trait. No trait ‘passes’ any property to anything else unless you specifically do it via Global properties.
You will need to use a Trigger and set the name of the piece into a Global Property (say called DieTarget) using a Set Global Property trait prior to issuing the Global Hotkey. You can set the Global property to $PieceName$, so the Trigger can be in a prototype. Then, your die roller reports
I want to do the exact same thing, but can’t get it to work.
My prototype have three traits for this.
Trigger, listens for CTRL-6 and performs CTRL-P and ALT-6
The CTRL-P triggers a “Set global property”: Set value directly, selectedUnit=$PieceName$
Also, there is a global property on the module level called selectedUnit.
The ALT-6 triggers a “Global hotkey” that performs a SHIFT-6.
My dice button listens for SHIFT-6 and the report includes $selectedUnit$.
He… now that I tried it again, it worked. Maybe I had to close and start a new game?
Yeah, many changes in the editor can be tested as you make them but others need a restart. I would imagine fooling with Global Properties would require a restart in most cases as these are normally initiated on start (if Vassal works like other programming code I’ve worked with).
I’ve gotten into the habit of always restarting before testing as I had problems in the past that actually didn’t exist.
Thanks, @JoelCFC25. I added a key command for “Sendtogrid” which is the GKC to draw a chit. However, the report is 1 chit behind. I.e. the first chit is reported as blank, the second chit drawn says it’s the first one, and so on.
Thanks, Mark. I had no idea displaying the name of a counter would be so complicated! LOL
Here is what the prototype looks like to draw a chit and report which chit was drawn:
I also had to make sure the map setting for “Auto-report format for units modified on this map” was set to $message$
What I did for ‘Air & Armor - Wurzburg’ is to create a Die counter. players move it to target hex and select the type of dice roll they want. Mostly for PBEM players to save typing.
Suppose you have a Dice Button (or Symbolic Dice Button) that listens for the key commandrollDice (or perhaps a hotkey like Alt-6) and has a name like Dice
Note that if the name is a not a valid Java identifier - e.g., starts with a number as in 1d6, then you will need to use GetProperty below.
If your Dice Button (or Symbolic Dice Button) name is not a valid Java identifier e.g., starts with a number like in 1d6, then the expression should use GetProperty as in {GetProperty("1d6_result")}.
If you do need to store the die roll value, then
Add Global Hotkey trait to the Dice roller prototype
Global Hotkey set to rollDice (or Alt-6)
Set the Key Command to something like rollDiceTrampoline
Give it a meaningful description e.g., “Trampoline to global die roll”
Report format: Something like {"!"+BasicName+" rolled "+DiceRoll}
You can of course make more complicated actions take place according to the die roll and what the initiating command was. I use, for example, a similar approach in most of the modules I made to do automatised battle resolutions. That is, an Odds marker can roll a die, and based on the die roll, the combat resolution is automatically resolved.