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

    Problem with foreach

    Scheduled Pinned Locked Moved Map Making
    7 Posts 3 Posters 321 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 the error

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

      Does anyone see an error?

      <variableList>
      <variable name="MajorPower">
       <element name="Britain"/>
       <element name="Soviet_Union"/>
       <element name="United_States"/>
       <element name="Western_Europe"/>
      </variable>
      <variable name="NewUnit">
      <element name="aaGun1"/>
      <element name="APC"/>
      <element name="bomber_lr"/>
      <element name="fighter_jp"/>
      <element name="fighter_lr"/>
      <element name="fission_bomb"/>
      <element name="fusion_bomb"/>
      <element name="heavy_armor"/>
      <element name="heavy_transport"/>
      <element name="marine"/>
      <element name="nuclear_carrier"/>
      <element name="radar_cruiser"/>
      <element name="self-propelled_artillery"/>
      <element name="special_forces"/>
      <element name="submarine1"/>
      <element name="submarine2"/>
      <element name="submarine3"/>
      </variable>
      <variable name="NeutralArea">
      <element name="Afghanistan"/>
      <element name="Borneo/Celebes"/>
      <element name="Ethiopia"/>
      <element name="Finland"/>
      <element name="Iran"/>
      <element name="Ireland"/>
      <element name="Java"/>
      <element name="Rio de Oro"/>
      <element name="Spain"/>
      <element name="Sumatra"/>
      <element name="Sweden"/>
      <element name="Switzerland"/>
      <element name="Thailand"/>
      <element name="Tibet"/>
      </variable>
      </variableList>
       <!--
      <attachment name="conditionAttachmentIrelandNon_Aligned" attachTo="Non_Aligned" javaClass="games.strategy.triplea.attachments.RulesAttachment" type="player">
            <option name="directOwnershipTerritories" value="Ireland" count="1"/>
      </attachment>
      -->
      <attachment foreach="$NeutralArea$" name="conditionAttachment@NeutralArea@Non_Aligned" attachTo="Non_Aligned" javaClass="games.strategy.triplea.attachments.RulesAttachment" type="player">
            <option name="directOwnershipTerritories" value="@NeutralArea@" count="1"/>
      </attachment>
      
      Note that commented out code works.
      
      wc_sumptonW 1 Reply Last reply Reply Quote 1
      • wc_sumptonW Offline
        wc_sumpton @RogerCooper
        last edited by

        @rogercooper

        variableList section is within attachmentList section. variableList needs its own section like resourceList, playerList, unitList.
        Most xml's have variableList section at the top prior to the map section.

        Cheers...

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

          @wc_sumpton said in Problem with foreach:

          @rogercooper

          variableList section is within attachmentList section. variableList needs its own section like resourceList, playerList, unitList.
          Most xml's have variableList section at the top prior to the map section.

          Cheers...

          Thank you for your help. That fixed it.

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

            @rogercooper I want to post my complete solution as it has some tricks people might want to use. I was surprised that you can use both a cartesian join "^" and a standard join ":" in the same foreach structure.

            Another neat trick is that you can use Export/Export game.xml file to resolve all the for eaches. Useful if you want to check that the result is correct or if you need to customize some entries.

            <variableList>
            <variable name="MajorPower">
             <element name="Britain"/>
             <element name="Soviet_Union"/>
             <element name="United_States"/>
             <element name="Western_Europe"/>
            </variable>
            <variable name="NeutralArea">
            <element name="Afghanistan"/>
            <element name="Borneo/Celebes"/>
            <element name="Ethiopia"/>
            <element name="Finland"/>
            <element name="Iran"/>
            <element name="Ireland"/>
            <element name="Java"/>
            <element name="Rio de Oro"/>
            <element name="Spain"/>
            <element name="Sumatra"/>
            <element name="Sweden"/>
            <element name="Switzerland"/>
            <element name="Thailand"/>
            <element name="Tibet"/>
            </variable>
            <variable name="NeutralSetup">
            <element name="infantry"/>
            <element name="infantry"/>
            <element name="infantry:infantry"/>
            <element name="infantry:infantry:infantry"/>
            <element name="infantry:armor:fighter"/>
            <element name="infantry"/>
            <element name="infantry"/>
            <element name="infantry"/>
            <element name="infantry:infantry:infantry:infantry:armor:fighter"/>
            <element name="infantry"/>
            <element name="infantry:infantry:infantry:armor:fighter"/>
            <element name="infantry:infantry:infantry:fighter"/>
            <element name="infantry:infantry"/>
            <element name="infantry:infantry"/>
            </variable>
            </variableList>
            
            

            and

            <attachment name="conditionAttachmentEveryTurn" attachTo="United_States" javaClass="games.strategy.triplea.attachments.RulesAttachment" type="player">
            <option name="rounds" value="1-100"/>
            </attachment>
            
            <attachment foreach="$NeutralArea$" name="conditionAttachment@NeutralArea@Non_Aligned" attachTo="Non_Aligned" javaClass="games.strategy.triplea.attachments.RulesAttachment" type="player">
                  <option name="directOwnershipTerritories" value="@NeutralArea@" count="1"/>
            </attachment>
            
            <attachment foreach="$NeutralArea$" name="triggerAttachment@NeutralArea@RemoveUnits" attachTo="Non_Aligned" javaClass="games.strategy.triplea.attachments.TriggerAttachment" type="player">
            <option name="players" value="Non_Aligned"/>
            <option name="uses" value="1"/>
            <option name="removeUnits" value="@NeutralArea@:All" count="5"/>
            </attachment>
            <attachment foreach="$MajorPower$^$NeutralArea$:$NeutralSetup$" name="triggerAttachment@MajorPower@@NeutralArea@" attachTo="@MajorPower@" javaClass="games.strategy.triplea.attachments.TriggerAttachment" type="player">
            <option name="conditions" value="conditionAttachmentEveryTurn"/>
            <option name="conditions" value="conditionAttachment@NeutralArea@Non_Aligned"/>
            <option name="players" value="@MajorPower@"/>
            <option name="chance" value="1:80"/>
            <option name="chanceIncrementOnFailure" value="1"/>
            <option name="when" value="before:@MajorPower@Purchase"/>
            <option name="placement" value="@NeutralArea@:@NeutralSetup@" />
            <option name="changeOwnership" value="@NeutralArea@:Non_Aligned:@MajorPower@:false"/>
            <option name="activateTrigger" value="triggerAttachment@NeutralArea@RemoveUnits:1:false:false:false:false"/>
            <option name="uses" value="1"/>
            </attachment>
            
            
            wc_sumptonW 1 Reply Last reply Reply Quote 3
            • wc_sumptonW Offline
              wc_sumpton @RogerCooper
              last edited by

              @rogercooper

              First off, I applauded the fantastic skill demonstrated. Next, I would like to humbly apologize.

              During the discussion under topic Transferring Unit Control when asked "Ireland changes ownership, but the unit remains Non_Aligned" the proper reply should have been "The units in Ireland will only change at Non_Aligned endTurn step. Using 'changeUnitOwners' with a value 'Soviet_Union' for Ireland means that any Non_Aligned infantry unit in Ireland will change to Soviet_Union control during Non_Aligned endTurn step, irregardless of territory ownership."
              I did not understand then the difference between 'changeUnitOwners' and 'captureUnitOnEnteringBy'.

              What happens if one of Non_Aligned units change either by setup or combat. IMHO 'captureUnitOnEnteringBy' would work much better.

              Again, I am sorry for any confusion or problems I may have caused. And again, the coding presented shows great skill.

              Cheers...

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

                @wc_sumpton There is no Non_Aligned turn step. Non_Aligned is a nominal player that is collection of territories and units that don't anything except defend. They have no steps. This is probably why your suggestions were not working.

                I can't leave them as neutral because

                • You can only change control of territory if it has actual player assigned to it.
                • I needed to allow the Soviet_Union to attack Non_Aligned territories but not the others

                I was surprised that foreach="$MajorPower$^$NeutralArea$:$NeutralSetup$" worked. The variable system was well coded..

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

                  @rogercooper said in Problem with foreach:

                  The variable system was well coded..

                  yea redrum did that. He was working on TWW and realized he needed about 1500 triggers so said F it and wrote the code.

                  But you probably already knew that 🙂

                  1 Reply Last reply Reply Quote 1

                  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