TripleA Logo TripleA Forum
    • TripleA Website
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Tags
    • Register
    • Login

    Problem with foreach

    Scheduled Pinned Locked Moved Map Making
    foreach
    11 Posts 3 Posters 3.0k Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • RogerCooperR Offline
      RogerCooper
      last edited by

      I am receiving this error with a foreach loop

      GameParseException: Attachment has invalid variables in foreach: $Major_Power$

      Here is my code

      <variable name="Major_Power">
            <element name="Soviet_Union"/>
            <element name="Western_Europe"/>
            <element name="Britain"/>
            <element name="United_States"/>
      </variable>   
      

      and

          <attachment foreach="$Major_Power$" name="triggerAttachmentsubmarine1@Major_Power@" attachTo="@Major_Power@" javaClass="games.strategy.triplea.attachments.TriggerAttachment" type="player">
            <option name="conditions" value="conditionAttachmentEveryTurn" />
            <option name="purchase" value="submarine1" count="1" />
            <option name="players" value="@Major_Power@" />
            <option name="chance" value="1:20" />
            <option name="chanceIncrementOnFailure" value="1" />
            <option name="when" value="before:@Major_Power@Purchase" />
            <option name="productionRule" value="production@Major_Power@:buysubmarine1"/>
            <option name="uses" value="1"/>
          </attachment>
      

      Any idea what the problem is?

      B W 2 Replies Last reply Reply Quote 0
      • B Offline
        beelee @RogerCooper
        last edited by

        @rogercooper

        @wc_sumpton would be the one to ask. I still struggle with foreach myself 🙂

        RogerCooperR 1 Reply Last reply Reply Quote 1
        • RogerCooperR Offline
          RogerCooper @beelee
          last edited by

          @beelee I have used foreach successfully before.

          B 1 Reply Last reply Reply Quote 0
          • B Offline
            beelee @RogerCooper
            last edited by

            @rogercooper

            I have as well just not always 🙂 Just pinging wc so he'll see it

            1 Reply Last reply Reply Quote 0
            • W Offline
              wc_sumpton @RogerCooper
              last edited by

              @rogercooper

              Why "players" when this will be the same as "attachTo"? Just a question?

              "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.

              Cheers...

              RogerCooperR 1 Reply Last reply Reply Quote 2
              • W Offline
                wc_sumpton
                last edited by

                @rogercooper said in Problem with foreach:

                Major_Power

                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 ":".

                There could be other problems, but without more information, I'm just shooting fish in a barrel.

                Cheers...

                RogerCooperR 1 Reply Last reply Reply Quote 3
                • RogerCooperR Offline
                  RogerCooper @wc_sumpton
                  last edited by RogerCooper

                  @wc_sumpton said in Problem with foreach:

                  @rogercooper said in Problem with foreach:

                  Major_Power

                  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 ":".
                  Cheers...

                  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

                  1 Reply Last reply Reply Quote 0
                  • RogerCooperR Offline
                    RogerCooper @wc_sumpton
                    last edited by

                    @wc_sumpton said in Problem with foreach:

                    @rogercooper

                    Why "players" when this will be the same as "attachTo"? Just a question?

                    "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.

                    Cheers...

                    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.

                    RogerCooperR W 2 Replies Last reply Reply Quote 0
                    • RogerCooperR Offline
                      RogerCooper @RogerCooper
                      last edited by

                      @rogercooper I tried simplifying the situation.

                      <variable name="Major_Power">
                            <element name="United_States"/>
                      </variable>   
                      
                          <attachment foreach="$Major_Power$" name="triggerAttachmentsubmarine1United_States" attachTo="United_States" javaClass="games.strategy.triplea.attachments.TriggerAttachment" type="player">
                            <option name="conditions" value="conditionAttachmentEveryTurn" />
                            <option name="purchase" value="submarine1" count="1" />
                            <option name="players" value="United_States" />
                            <option name="chance" value="1:20" />
                            <option name="chanceIncrementOnFailure" value="1" />
                            <option name="when" value="before:United_StatesPurchase" />
                            <option name="productionRule" value="productionUnited_States:buysubmarine1"/>
                            <option name="uses" value="1"/>
                          </attachment>
                      
                      

                      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.

                      Here is some code that definitely does work

                          <attachment foreach="$LandArea$" name="triggerAttachmentZombiesrussianZombie@LandArea@" attachTo="Zombies" javaClass="games.strategy.triplea.attachments.TriggerAttachment" type="player">
                            <option name="conditions" value="conditionAttachmentEveryTurn" />
                            <option name="placement" value="@LandArea@:zombie" count="1" />
                            <option name="players" value="Zombies" />
                            <option name="chance" value="2:70" />
                            <option name="when" value="before:russianPurchase" />
                          </attachment>
                      
                      RogerCooperR 1 Reply Last reply Reply Quote 0
                      • RogerCooperR Offline
                        RogerCooper @RogerCooper
                        last edited by

                        @rogercooper SOLVED IT. I forgot the variableList tags.

                        1 Reply Last reply Reply Quote 4
                        • W Offline
                          wc_sumpton @RogerCooper
                          last edited by

                          @rogercooper said in Problem with foreach:

                          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.

                          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.

                          @rogercooper said in Problem with foreach:

                          @rogercooper SOLVED IT. I forgot the variableList tags.

                          Would have never guessed this! Happy you have figured it out.

                          Cheers...

                          1 Reply Last reply Reply Quote 2

                          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                          With your input, this post could be even better 💗

                          Register Login
                          • 1 / 1
                          • First post
                            Last post
                          Copyright © 2016-2018 TripleA-Devs | Powered by NodeBB Forums