stopping a loop in a loop?

takethat

Active Member
Reaction score
12
is that posible in gui to stop a loop inside that loop?

for example, a loop is going to loop for 10 times, but in certain circustances, the loop need to be stop at the fifth time
 

Kikac_NNGK

Well-Known Member
Reaction score
33
I think u cant stop the loop in the loop actions
Stopping must be outside the loop actions
 

Nexor

...
Reaction score
74
yes, you can in JASS, using the exitwhen line

example

local integer i = 1
local integer exit = 10

loop
exitwhen i >= exit
if IsSunnyDay(today) == true then
set exit = 5
endif
set i = i + 1
endloop
 

takethat

Active Member
Reaction score
12
yeah, i understand jass can do so, but i asking is there a way to do so in GUI?
 

GooS

Azrael
Reaction score
154
Trigger:
  • Untitled Trigger 001
    • Events
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 10, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Triggering unit) Equal to (Attacked unit)
            • Then - Actions
              • Custom script: set bj_forLoopAIndex = bj_forLoopAIndexEnd - 1
            • Else - Actions


If something returns true then the custom script will set the loop index to end index -1 because the increment comes last in Integer A loop. This will make it break the loop!
 

takethat

Active Member
Reaction score
12
Trigger:
  • test grap
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to Test Grap (E)
    • Actions
      • For each (Integer A) from 1 to 10, do (Actions)
        • Loop - Actions
          • Game - Display to (All players) the text: (String((Integer A)))
          • Wait 1.00 seconds
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Test Equal to True
            • Then - Actions
              • Custom script: set bj_forLoopAIndex = bj_forLoopAIndex - 1
            • Else - Actions


this results in the loop keep repeating on the same number, i use show text to show the number of integer A,

as the test equal to true, the loop repeat non stop.


edit: i change abit the trigger, it seems working as the number only show 1 when the spell is cast and Test is equal to True.

though i need some 1 to varify if this is right.

Trigger:
  • test grap
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to Test Grap (E)
    • Actions
      • Set Int_Temp = 10
      • For each (Integer A) from 1 to Int_Temp, do (Actions)
        • Loop - Actions
          • Game - Display to (All players) the text: (String((Integer A)))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Test Equal to True
            • Then - Actions
              • Custom script: set bj_forLoopAIndex = udg_Int_Temp
            • Else - Actions
          • Wait 1.00 seconds
 

Tom_Kazansky

--- wraith it ! ---
Reaction score
157
err... I think this would work, too.
Trigger:
  • Custom script: exitwhen true



Trigger:
  • test grap
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to Test Grap (E)
    • Actions
      • Set Int_Temp = 10
      • For each (Integer A) from 1 to Int_Temp, do (Actions)
        • Loop - Actions
          • Game - Display to (All players) the text: (String((Integer A)))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Test Equal to True
            • Then - Actions
              • Custom script: exitwhen true
            • Else - Actions
          • Wait 1.00 seconds
 

GooS

Azrael
Reaction score
154
err... I think this would work, too.

I though about telling him to use one of thoose, but, can a loop have two exitwhen's? seems like it would cause issues, converted the loop will already have one, telling it exitwhen Integer A = Int_temp as you named the variable.

Trigger:
  • Custom script: set bj_forLoopAIndex = bj_forLoopAIndexEnd - 1


This would simply set the current Integer A to AIndexEnd - 1, because converted the last Integer A = integer A + 1 comes after, making it stop when this is run.
 

Romek

Super Moderator
Reaction score
964
> I though about telling him to use one of thoose, but, can a loop have two exitwhen's? seems like it would cause issues
Mind explaining? :rolleyes:

'exitwhen true' is fine. It'll exit the loop at the point of the custom script.
 

GooS

Azrael
Reaction score
154
> I though about telling him to use one of thoose, but, can a loop have two exitwhen's? seems like it would cause issues
Mind explaining?

'exitwhen true' is fine. It'll exit the loop at the point of the custom script.

The GUI loop already has an exitwhen condition, adding another one made me think there would be issues, don't really know why, just seemed like it :)

Huh:

JASS:
function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 10
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        if ( Trig_Untitled_Trigger_001_Func001Func001C() ) then
            exitwhen true
        else
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
endfunction


But it didn't display any errors, so It seems fine, my thoughts were basically the same as you don't add two "else" in an if statement, note "else" not "elseif".

//==GooS
 

Romek

Super Moderator
Reaction score
964
You can have 23 'exitwhen not (false and not (true != false))' for all I care.
I don't think there's any realistic limit on the amount of exitwhen's. :)
 

takethat

Active Member
Reaction score
12
sorry i didnt make it clear, but

Trigger:
  • Custom script: set bj_forLoopAIndex = bj_forLoopAIndexEnd - 1


doesnt work, since i put a wait in my trigger when testing, it didnt goes into infinite loop, but as it show the same number over and over again, i guess it WILL lead into an infinite loop.

using integer variable method solve the case, and exitwhen also work fine.

i think when exitwhen = true, it escape the loop.

so its like a maze can have multiple exit.

anyway the problem is solve.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      • Ghan
        Administrator - Servers are fun

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top