<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Problem with foreach]]></title><description><![CDATA[<p dir="auto">I am receiving this error with a foreach loop</p>
<p dir="auto">GameParseException: Attachment has invalid variables in foreach: $Major_Power$</p>
<p dir="auto">Here is my code</p>
<pre><code>&lt;variable name="Major_Power"&gt;
      &lt;element name="Soviet_Union"/&gt;
      &lt;element name="Western_Europe"/&gt;
      &lt;element name="Britain"/&gt;
      &lt;element name="United_States"/&gt;
&lt;/variable&gt;   
</code></pre>
<p dir="auto">and</p>
<pre><code>    &lt;attachment foreach="$Major_Power$" name="triggerAttachmentsubmarine1@Major_Power@" attachTo="@Major_Power@" javaClass="games.strategy.triplea.attachments.TriggerAttachment" type="player"&gt;
      &lt;option name="conditions" value="conditionAttachmentEveryTurn" /&gt;
      &lt;option name="purchase" value="submarine1" count="1" /&gt;
      &lt;option name="players" value="@Major_Power@" /&gt;
      &lt;option name="chance" value="1:20" /&gt;
      &lt;option name="chanceIncrementOnFailure" value="1" /&gt;
      &lt;option name="when" value="before:@Major_Power@Purchase" /&gt;
      &lt;option name="productionRule" value="production@Major_Power@:buysubmarine1"/&gt;
      &lt;option name="uses" value="1"/&gt;
    &lt;/attachment&gt;
</code></pre>
<p dir="auto">Any idea what the problem is?</p>
]]></description><link>https://forums.triplea-game.org/topic/4157/problem-with-foreach</link><generator>RSS for Node</generator><lastBuildDate>Sat, 14 Nov 2026 20:16:43 GMT</lastBuildDate><atom:link href="https://forums.triplea-game.org/topic/4157.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 03 Jun 2025 19:29:29 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem with foreach on Thu, 05 Jun 2025 00:25:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rogercooper" aria-label="Profile: rogercooper">@<bdi>rogercooper</bdi></a> said in <a href="/post/70616">Problem with foreach</a>:</p>
<blockquote>
<p dir="auto">I was copying existing code. If I understand correctly, "attachTo" is arbitrary and "players" is required to be sure that the correct player is involved.</p>
</blockquote>
<p dir="auto">If "players" is used, then "attachTo" is ignored. I only use "players" when the trigger affects more than one player. But to each his own.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rogercooper" aria-label="Profile: rogercooper">@<bdi>rogercooper</bdi></a> said in <a href="/post/70620">Problem with foreach</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rogercooper" aria-label="Profile: rogercooper">@<bdi>rogercooper</bdi></a> SOLVED IT. I forgot the variableList tags.</p>
</blockquote>
<p dir="auto">Would have never guessed this! Happy you have figured it out.</p>
<p dir="auto">Cheers...</p>
]]></description><link>https://forums.triplea-game.org/post/70626</link><guid isPermaLink="true">https://forums.triplea-game.org/post/70626</guid><dc:creator><![CDATA[wc_sumpton]]></dc:creator><pubDate>Thu, 05 Jun 2025 00:25:27 GMT</pubDate></item><item><title><![CDATA[Reply to Problem with foreach on Wed, 04 Jun 2025 19:58:15 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rogercooper" aria-label="Profile: rogercooper">@<bdi>rogercooper</bdi></a> SOLVED IT. I forgot the variableList tags.</p>
]]></description><link>https://forums.triplea-game.org/post/70620</link><guid isPermaLink="true">https://forums.triplea-game.org/post/70620</guid><dc:creator><![CDATA[RogerCooper]]></dc:creator><pubDate>Wed, 04 Jun 2025 19:58:15 GMT</pubDate></item><item><title><![CDATA[Reply to Problem with foreach on Wed, 04 Jun 2025 19:51:33 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rogercooper" aria-label="Profile: rogercooper">@<bdi>rogercooper</bdi></a> I tried simplifying the situation.</p>
<pre><code>&lt;variable name="Major_Power"&gt;
      &lt;element name="United_States"/&gt;
&lt;/variable&gt;   
</code></pre>
<pre><code>    &lt;attachment foreach="$Major_Power$" name="triggerAttachmentsubmarine1United_States" attachTo="United_States" javaClass="games.strategy.triplea.attachments.TriggerAttachment" type="player"&gt;
      &lt;option name="conditions" value="conditionAttachmentEveryTurn" /&gt;
      &lt;option name="purchase" value="submarine1" count="1" /&gt;
      &lt;option name="players" value="United_States" /&gt;
      &lt;option name="chance" value="1:20" /&gt;
      &lt;option name="chanceIncrementOnFailure" value="1" /&gt;
      &lt;option name="when" value="before:United_StatesPurchase" /&gt;
      &lt;option name="productionRule" value="productionUnited_States:buysubmarine1"/&gt;
      &lt;option name="uses" value="1"/&gt;
    &lt;/attachment&gt;

</code></pre>
<p dir="auto">This gets the error. If I remove **foreach="$Major_Power$" ** the error disappears. (I also tried without the underscore to no avail). I also tried removing every option in trigger.</p>
<p dir="auto">Here is some code that definitely does work</p>
<pre><code>    &lt;attachment foreach="$LandArea$" name="triggerAttachmentZombiesrussianZombie@LandArea@" attachTo="Zombies" javaClass="games.strategy.triplea.attachments.TriggerAttachment" type="player"&gt;
      &lt;option name="conditions" value="conditionAttachmentEveryTurn" /&gt;
      &lt;option name="placement" value="@LandArea@:zombie" count="1" /&gt;
      &lt;option name="players" value="Zombies" /&gt;
      &lt;option name="chance" value="2:70" /&gt;
      &lt;option name="when" value="before:russianPurchase" /&gt;
    &lt;/attachment&gt;
</code></pre>
]]></description><link>https://forums.triplea-game.org/post/70619</link><guid isPermaLink="true">https://forums.triplea-game.org/post/70619</guid><dc:creator><![CDATA[RogerCooper]]></dc:creator><pubDate>Wed, 04 Jun 2025 19:51:33 GMT</pubDate></item><item><title><![CDATA[Reply to Problem with foreach on Wed, 04 Jun 2025 19:04:17 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/wc_sumpton" aria-label="Profile: wc_sumpton">@<bdi>wc_sumpton</bdi></a> said in <a href="/post/70607">Problem with foreach</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rogercooper" aria-label="Profile: rogercooper">@<bdi>rogercooper</bdi></a></p>
<p dir="auto">Why "players" when this will be the same as "attachTo"? Just a question?</p>
<p dir="auto">"GameParseException: Attachment has invalid variables in foreach: $Major_Power$" usually means one of the variables are wrong. Could be a miss spelling. So, recheck there. Beyond that it's hard to tell with the information given. Sorry.</p>
<p dir="auto">Cheers...</p>
</blockquote>
<p dir="auto">I was copying existing code. If I understand correctly, "attachTo" is arbitrary and "players" is required to be sure that the correct player is involved.</p>
]]></description><link>https://forums.triplea-game.org/post/70616</link><guid isPermaLink="true">https://forums.triplea-game.org/post/70616</guid><dc:creator><![CDATA[RogerCooper]]></dc:creator><pubDate>Wed, 04 Jun 2025 19:04:17 GMT</pubDate></item><item><title><![CDATA[Reply to Problem with foreach on Wed, 04 Jun 2025 18:59:40 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/wc_sumpton" aria-label="Profile: wc_sumpton">@<bdi>wc_sumpton</bdi></a> said in <a href="/post/70613">Problem with foreach</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rogercooper" aria-label="Profile: rogercooper">@<bdi>rogercooper</bdi></a> said in <a href="/post/70592">Problem with foreach</a>:</p>
<blockquote>
<p dir="auto">Major_Power</p>
</blockquote>
<p dir="auto">After further review, your problem may be the "_". Instead of "Soviet Union", there is "Soviet_Union". The "attachTo" (and "players") must be the actual player name. If there are both, player "Soviet Union" and "productionSoviet_Union" then you will need two variable lists and they will need to be separated by the carrot "^" and not the colon ":".<br />
Cheers...</p>
</blockquote>
<p dir="auto">It turns out that the production frontier was misnamed. However, fixing that did not resolve the issue. I am now using "Soviet_Union" in all places</p>
]]></description><link>https://forums.triplea-game.org/post/70615</link><guid isPermaLink="true">https://forums.triplea-game.org/post/70615</guid><dc:creator><![CDATA[RogerCooper]]></dc:creator><pubDate>Wed, 04 Jun 2025 18:59:40 GMT</pubDate></item><item><title><![CDATA[Reply to Problem with foreach on Wed, 04 Jun 2025 11:47:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rogercooper" aria-label="Profile: rogercooper">@<bdi>rogercooper</bdi></a> said in <a href="/post/70592">Problem with foreach</a>:</p>
<blockquote>
<p dir="auto">Major_Power</p>
</blockquote>
<p dir="auto">After further review, your problem may be the "_". Instead of "Soviet Union", there is "Soviet_Union". The "attachTo" (and "players") must be the actual player name. If there are both, player "Soviet Union" and "productionSoviet_Union" then you will need two variable lists and they will need to be separated by the carrot "^" and not the colon ":".</p>
<p dir="auto">There could be other problems, but without more information, I'm just shooting fish in a barrel.</p>
<p dir="auto">Cheers...</p>
]]></description><link>https://forums.triplea-game.org/post/70613</link><guid isPermaLink="true">https://forums.triplea-game.org/post/70613</guid><dc:creator><![CDATA[wc_sumpton]]></dc:creator><pubDate>Wed, 04 Jun 2025 11:47:12 GMT</pubDate></item><item><title><![CDATA[Reply to Problem with foreach on Wed, 04 Jun 2025 03:04:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rogercooper" aria-label="Profile: rogercooper">@<bdi>rogercooper</bdi></a></p>
<p dir="auto">Why "players" when this will be the same as "attachTo"? Just a question?</p>
<p dir="auto">"GameParseException: Attachment has invalid variables in foreach: $Major_Power$" usually means one of the variables are wrong. Could be a miss spelling. So, recheck there. Beyond that it's hard to tell with the information given. Sorry.</p>
<p dir="auto">Cheers...</p>
]]></description><link>https://forums.triplea-game.org/post/70607</link><guid isPermaLink="true">https://forums.triplea-game.org/post/70607</guid><dc:creator><![CDATA[wc_sumpton]]></dc:creator><pubDate>Wed, 04 Jun 2025 03:04:20 GMT</pubDate></item><item><title><![CDATA[Reply to Problem with foreach on Tue, 03 Jun 2025 22:11:11 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rogercooper" aria-label="Profile: rogercooper">@<bdi>rogercooper</bdi></a></p>
<p dir="auto">I have as well just not always <img src="https://forums.triplea-game.org/assets/plugins/nodebb-plugin-emoji/emoji/android/1f642.png?v=fbe62970dd5" class="not-responsive emoji emoji-android emoji--slightly_smiling_face" style="height:1.4em;width:auto;vertical-align:middle" title=":)" alt="🙂" /> Just pinging wc so he'll see it</p>
]]></description><link>https://forums.triplea-game.org/post/70601</link><guid isPermaLink="true">https://forums.triplea-game.org/post/70601</guid><dc:creator><![CDATA[beelee]]></dc:creator><pubDate>Tue, 03 Jun 2025 22:11:11 GMT</pubDate></item><item><title><![CDATA[Reply to Problem with foreach on Tue, 03 Jun 2025 22:09:11 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/beelee" aria-label="Profile: beelee">@<bdi>beelee</bdi></a> I have used foreach successfully before.</p>
]]></description><link>https://forums.triplea-game.org/post/70600</link><guid isPermaLink="true">https://forums.triplea-game.org/post/70600</guid><dc:creator><![CDATA[RogerCooper]]></dc:creator><pubDate>Tue, 03 Jun 2025 22:09:11 GMT</pubDate></item><item><title><![CDATA[Reply to Problem with foreach on Tue, 03 Jun 2025 21:53:01 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rogercooper" aria-label="Profile: rogercooper">@<bdi>rogercooper</bdi></a></p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/wc_sumpton" aria-label="Profile: wc_sumpton">@<bdi>wc_sumpton</bdi></a> would be the one to ask. I still struggle with foreach myself <img src="https://forums.triplea-game.org/assets/plugins/nodebb-plugin-emoji/emoji/android/1f642.png?v=fbe62970dd5" class="not-responsive emoji emoji-android emoji--slightly_smiling_face" style="height:1.4em;width:auto;vertical-align:middle" title=":)" alt="🙂" /></p>
]]></description><link>https://forums.triplea-game.org/post/70599</link><guid isPermaLink="true">https://forums.triplea-game.org/post/70599</guid><dc:creator><![CDATA[beelee]]></dc:creator><pubDate>Tue, 03 Jun 2025 21:53:01 GMT</pubDate></item></channel></rss>