Can someone explain what "For Loop Integer A" does?

staind25

TH.net Regular
Reaction score
7
I'm using (Integer A) in a variable array but I'm not sure if it does what I want it to do. I can't find any tutorials on loops either.

I posted a topic last night on what I WANT it to do...it's copied below:

I'm in the process of setting the variable to a specific array. The goal is...if array 0 is NOT empty, check array 1. If array 1 is NOT empty, check array 2...and so on, until it finds an empty array.

The alternative to the loop is a very long list of if/then/else statements which I'd rather avoid if I can. I'd essentially have to have if/then/else/if/then/else 12 times...it'd be ridiculous and probably really slow for the machine to calculate.


So...will a loop solve my problem? If so, can you please explain how this is done?


Thanks much! I know it's a lot of reading/problem solving and I really appreciate your time and effort.
 

rover2341

Is riding a roller coaster...Wee!
Reaction score
113
Integer A is a variable of type integer. and the loop will change its value.

Sample 1:

When this trigger runs, the variable called, "Integer A" Will become one. Then after all the actions in the loop have been called, It will change the Value of "Integer A" to 2. It will do this intill it gets to 10.

This will display to the screen.

1
2
3
4
5
6
7
8
9
10

Trigger:
  • Basic Loop
    • Events
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 10, do (Actions)
        • Loop - Actions
          • Game - Display to (All players) the text: (String((Integer A)))


Sample 2
:

This sample, I made a variable of type int called myLoopVar. I Made in Array of integers called myArray.
When the trigger is called, myLoopVar is set to zero, and runs throw the first 10 things in my array. It stops as soon as it finds a zero value.

Trigger:
  • If Value In Array Equals 0 Stop
    • Events
    • Conditions
    • Actions
      • For each (Integer myLoopVar) from 0 to 10, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • myArray[myLoopVar] Equal to 0
            • Then - Actions
              • Set myLoopVar = 10
              • Game - Display to (All players) the text: Exit Array
            • Else - Actions
              • Game - Display to (All players) the text: Use IT

Does this answer your Question?
 

staind25

TH.net Regular
Reaction score
7
Ohh okay thank you. Yes, that answers my original question, but now I have another XD

I want to create a loop that will basically say, "If array 0 is empty, use it, else check array 1" until it finds an empty array. Can I do this?

Thanks.
 

Emu.Man00

New Member
Reaction score
41
Yes, you can do it like this (freehand):

Code:
for loop integer a from 0 to 11
   if not yourVariable[integer A] = (null/no unit/etc.) then
      (your code)
   endif

I'm not sure how to exit loops in gui but you might want to do that to if you only want this to run for one non-empty variable.
Also, you would have to remember to set the variables back to empty values if you plan on using this trigger repeatedly.
 

rover2341

Is riding a roller coaster...Wee!
Reaction score
113
I want to create a loop that will basically say, "If array 0 is empty, use it, else check array 1" until it finds an empty array. Can I do this?

Sample 2 Does that.
 

staind25

TH.net Regular
Reaction score
7
Thank you so much! I'll experiment with this a little and hopefully I'll get it to work soon :D Your second sample question helped a ton, too.
 

Panda

New Member
Reaction score
3
You can also do it without the "for loop":
Trigger:
  • Trigger
    • Events
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • array[count] Equal to True
        • Then - Actions
          • -------- Whatever --------
        • Else - Actions
          • Set count = (count + 1)
          • Trigger - Run (This trigger) (ignoring conditions)
 

staind25

TH.net Regular
Reaction score
7
Wow, you guys are full of good ideas, haha. Thanks for this suggestion as well. If I can't get the loop to work I'll do this :)

I just wanted to avoid checking every array index by itself (e.g., if Variable[0] is empty, then ---, else if Variable[1] is empty, and so on)...that would've taken a ton of triggering and would probably be very inefficient for the machine, too.
 

staind25

TH.net Regular
Reaction score
7
Well, it works :) Now I'm running into OTHER issues (Related to the ability I'm working on, but not this portion of the trigger) which I may have to make a new topic about.

Thanks for all of the suggestions everyone! Hopefully you don't mind more questions in the near future!
 
General chit-chat
Help Users

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top