HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

GUI Bug, Loops in Conditions

12-29-2008, 12:34 PM#1
akolyt0r
Over at TheHelper, kirbyman1 just found a sweet bug, which enables GUI users to use Loops in Conditions see here:

http://www.thehelper.net/forums/showthread.php?t=115281

it works like following:
place a "if then else (multiple)" action, add a condition, and then change the "if then else (multiple)" to a loop... so you got a condition in a loop.
no you have to make an additionally loop below it, and drag and drop your first loop in this loops action block.
Now change the outer loop in a "if then else (multiple)"

EDIT:
Sorry my example sucked xD...

EXample by Artificial
Trigger:
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Collapse For each (Integer A) from 1 to InstanceCount, do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Dying unit) Equal to Casters[(Integer A)]
Collapse Then - Actions
Custom script: return true
Else - Actions
Custom script: return false
Collapse Then - Actions
Unit - Kill Targets[(Integer A)]
Else - Actions

generates following code:
Collapse JASS:
function Trig_Example_Func001Func002Func001C takes nothing returns boolean
    if ( not ( GetTriggerUnit() == udg_Caster[GetForLoopIndexA()] ) ) then
        return false
    endif
    return true
endfunction

function Trig_Example_Func001C takes nothing returns boolean
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 10
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        if ( Trig_Example_Func001Func002Func001C() ) then
            return true
        else
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    return false
    return true
endfunction

function Trig_Example_Actions takes nothing returns nothing
    if ( Trig_Example_Func001C() ) then
        call KillUnit( udg_Targets[GetForLoopIndexA()] )
    else
    endif
endfunction

//===========================================================================
function InitTrig_Example takes nothing returns nothing
    set gg_trg_Example = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Example, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddAction( gg_trg_Example, function Trig_Example_Actions )
endfunction
12-29-2008, 01:51 PM#2
Bobo_The_Kodo
Wait... how is that a bug? Why wouldn't you be able to do that?
12-29-2008, 03:22 PM#3
dead_or_alivex
With that bug, you can change this:

Trigger:
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
((Triggering unit) is A structure) Equal to True
Then - Actions
Else - Actions

... to this:

Trigger:
For each (Integer A) from 1 to 10, do (Actions)
Collapse Loop - Actions
((Triggering unit) is A structure) Equal to True
... by changing the GUI If block to a For Loop block after you place a condition inside. Apparently the two are interchangeable and the result is some buggy generated code (on its own).

The code in the OP shows how, by doing this multiple times, you can end up with complex loops in Conditions blocks.

Very interesting bug; it could help GUI users make more logical, structured code, I guess.
12-29-2008, 03:49 PM#4
Fireeye
Instead of the one you posted in Post #1, you could also make
Trigger:
For each (Integer A) from 1 to InstanceCount, do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Dying unit) Equal to Casters[(Integer A)]
Collapse Then - Actions
Unit - Kill Targets[(Integer A)]
Else - Actions
I personally also can not really think about any situation where you could use your idea better.
Well, i guess i'm too much into vJASS.
12-29-2008, 05:47 PM#5
Kyrbi0
This sounds like it's really helpful (as a GUI user), but I can't think of an application of this right now...

Anyway, thanks for posting here.
12-29-2008, 07:44 PM#6
akolyt0r
Quote:
Originally Posted by Fireeye
Instead of the one you posted in Post #1, you could also make
Trigger:
For each (Integer A) from 1 to InstanceCount, do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Dying unit) Equal to Casters[(Integer A)]
Collapse Then - Actions
Unit - Kill Targets[(Integer A)]
Else - Actions
I personally also can not really think about any situation where you could use your idea better.
Well, i guess i'm too much into vJASS.

yes ur right the example is not that good :)

but there can be applications where you can need something like that :)

hmm ....well most probably nothing can be achieved with this bug, which could not been achieved without the bug aswell, but perhaps it will make code sometimes more readable (After some time thinking about it i believe this will be probably pretty uncommon) .
12-29-2008, 08:25 PM#7
Strilanc
Not very different from placing the check in your actions, and using Skip Remaining Actions.

Actually, I'd recommend continuing to do that, since Blizzard might just fix this bug and royally **** your triggers.

[Haha, as if blizzard would fix a bug in the editor]
01-01-2009, 08:48 AM#8
Jazradel
I remember doing this accidently all the time (and being annoyed as crap about it) back in the day. Pity the bug is pretty much totally useless.
01-02-2009, 07:43 AM#9
Pyrogasm
I may be retarded, but I don't see how this is useful at all...

Seems like it just is another way to write something that was simple to write in the first place.
01-03-2009, 01:56 AM#10
Bobo_The_Kodo
Quote:
I may be retarded, but I don't see how this is useful at all...

Seems like it just is another way to write something that was simple to write in the first place.
/agree