Cannot cast TriggerAttachment to RulesAttachment
-
I'm getting a new (to me) error message for one of my custom triggers, and I don't understand what it means or how to fix it.
The error message is:
Could not parse:file:///C:/Users/jason/triplea/downloadedMaps/bbr5/games/bbr5.xml, map name: 'file:///C:/Users/jason/triplea/downloadedMaps/bbr5/games/bbr5.xml', Unexpected Exception while setting values for attachment: TriggerAttachment attached to: PlayerId named:Germans with name: triggerAttachment_Germans_AttemptMatureTech_0, Cannot cast games.strategy.triplea.attachments.TriggerAttachment to games.strategy.triplea.attachments.RulesAttachment java.lang.ClassCastException: Cannot cast games.strategy.triplea.attachments.TriggerAttachment to games.strategy.triplea.attachments.RulesAttachmentThe code triggering this error is:
<attachment foreach="$MatureTechDice$:$MatureTechOdds$^$AllTechPlayers$" name="triggerAttachment_@AllTechPlayers@_AttemptMatureTech_@MatureTechDice@" attachTo="@AllTechPlayers@" javaClass="games.strategy.triplea.attachments.TriggerAttachment" type="player"> <option name="chance" value="@MatureTechOdds@:100"/> <option name="trigger" value="triggerAttachment_@AllTechPlayers@_DiscoverTech"/> <option name="trigger" value="triggerAttachment_@AllTechPlayers@_ClearTech"/> </attachment>
Note that MatureTechDice and MatureTechOdds are each a <variableList> containing 11 variables, each of which is a string containing a positive integer, and AllTechPlayers is a <variableList> containing 8 variables, each of which is a string containing the name of a player.
This is a relatively complicated trigger, with double-nesting, but I have not had any problems with this type of nesting elsewhere in my code, and I don't understand what's going wrong here.
Does anyone have any advice?
-
Try swapping these around so AllTechPlayers is first. IIRC it matters that the paired variables lists must be the second set.
"$AllTechPlayers$^$MatureTechDice$:$MatureTechOdds$"
-
@thedog Thanks, but I tried that already -- got the same error message.
-
It doesn't seem to be a problem with the foreach mapping at all -- I get the same error message when I remove all the variables:
<attachment name="triggerAttachment_Germans_AttemptMatureTech_2" attachTo="Germans" javaClass="games.strategy.triplea.attachments.TriggerAttachment" type="player"> <option name="chance" value="2:100"/> <option name="trigger" value="triggerAttachment_Germans_DiscoverTech"/> <option name="trigger" value="triggerAttachment_Germans_ClearTech"/> </attachment>
-
The immediate problem was that I can't use "trigger" inside a triggerAttachment; the correct syntax is "activateTrigger."
However, I'm still getting an error message, although now it's a new error message. Here's the relevant code:
<attachment foreach="$AllTechPlayers$^$Technologies$" name="triggerAttachment_@AllTechPlayers@_DiscoverTech" attachTo="@AllTechPlayers@" javaClass="games.strategy.triplea.attachments.TriggerAttachment" type="player"> <option name="conditions" value="conditionAttachment_@AllTechPlayers@_IsDeveloping_@Technologies@"/> <option name="playerAttachmentName" value="RulesAttachment" count="conditionAttachment_@AllTechPlayers@_HasDeveloped_@Technologies@"/> <option name="playerProperty" value="switch" count="true"/> </attachment>
<attachment foreach="$AllTechPlayers$^$Technologies$" name="triggerAttachment_@AllTechPlayers@_ClearTech" attachTo="@AllTechPlayers@" javaClass="games.strategy.triplea.attachments.TriggerAttachment" type="player"> <option name="playerAttachmentName" value="RulesAttachment" count="conditionAttachment_@AllTechPlayers@_IsDeveloping_@Technologies@"/> <option name="playerProperty" value="switch" count="false"/> <option name="removeUnits" value="all:tech_token" count="50"/> </attachment>
<attachment foreach="$AllTechPlayers$^$Technologies$" name="triggerAttachment_@AllTechPlayers@_AttemptMatureTech" attachTo="@AllTechPlayers@" javaClass="games.strategy.triplea.attachments.TriggerAttachment" type="player"> <option name="playerAttachmentName" value="RulesAttachment" count="conditionAttachment_@AllTechPlayers@_HasDeveloped_@Technologies@"/> <option name="playerProperty" value="switch" count="true"/> </attachment> <attachment foreach="$AllTechPlayers$^$MatureTechDice$:$MatureTechOdds$" name="triggerAttachment_@AllTechPlayers@_AttemptMatureTech_@MatureTechDice@" attachTo="@AllTechPlayers@" javaClass="games.strategy.triplea.attachments.TriggerAttachment" type="player"> <option name="chance" value="@MatureTechOdds@:100"/> <option name="activateTrigger" value="triggerAttachment_@AllTechPlayers@_DiscoverTech"/> <option name="activateTrigger" value="triggerAttachment_@AllTechPlayers@_ClearTech"/> </attachment> <attachment foreach="$AllTechPlayers$^$MatureTechDice$:$MatureTechOdds$" name="userActionAttachment_@AllTechPlayers@_Choose_Mature_Tech_Effort_@MatureTechDice@" attachTo="Germans" javaClass="games.strategy.triplea.attachments.UserActionAttachment" type="player"> <option name="conditions" value="conditionAttachment_@AllTechPlayers@_HasFourTechTokens:conditionAttachment_@AllTechPlayers@_TechActionNotYetUsedThisTurn"/> <option name="activateTrigger" value="triggerAttachment_@AllTechPlayers@_AttemptMatureTech_@MatureTechDice@:1:false:false:false:false"/> <option name="activateTrigger" value="triggerAttachment_@AllTechPlayers@_TechActionUsed:1:false:false:false:false"/> <option name="text" value="BUY_TECH_@MatureTechDice@"/> <option name="attemptsPerTurn" value="1"/> <option name="costPU" value="@MatureTechDice@"/> </attachment>
And here's the error message:
Could not parse:file:///C:/Users/jason/triplea/downloadedMaps/bbr5/games/bbr5.xml, map name: 'file:///C:/Users/jason/triplea/downloadedMaps/bbr5/games/bbr5.xml', Unexpected Exception while setting values for attachment: TriggerAttachment attached to: PlayerId named:Germans with name: triggerAttachment_Germans_AttemptMatureTech_0, failed to set string property value to 'triggerAttachment_Germans_DiscoverTech' games.strategy.engine.data.MutableProperty$InvalidValueException: failed to set string property value to 'triggerAttachment_Germans_DiscoverTech'
-
Try completing "activateTrigger":
<attachment foreach="$AllTechPlayers$^$MatureTechDice$:$MatureTechOdds$" name="triggerAttachment_@AllTechPlayers@_AttemptMatureTech_@MatureTechDice@" attachTo="@AllTechPlayers@" javaClass="games.strategy.triplea.attachments.TriggerAttachment" type="player"> <option name="chance" value="@MatureTechOdds@:100"/> <option name="activateTrigger" value="triggerAttachment_@AllTechPlayers@_DiscoverTech:1:false:false:false:false"/> <option name="activateTrigger" value="triggerAttachment_@AllTechPlayers@_ClearTech:1:false:false:false:false"/> </attachment>
Cheers...
-
@wc_sumpton said in Cannot cast TriggerAttachment to RulesAttachment:
:1:false:false:false:false
Eeey, there we go, that works. Thank you!