How to avoid a nasty endless loop thingy?

Viikuna

No Marlo no game.
Reaction score
265
I was working with a little script and Im having problems to think any good and simple way to avoid an endless loop with custom events.

Code:
JASS:
library StuffLib

globals
    private trigger array Trigs
    private integer Total=0
endglobals

function TriggerRegisterStuffEvent takes trigger t returns nothing
    set Trigs[Total]=t
    set Total=Total+1
endfunction

function DoStuff takes stuff returns nothing
          local integer i=0     
 
         // stuff

         loop
            exitwhen i>=Total
            if IsTriggerEnabled(Trigs<i>) and TriggerEvaluate(Trigs<i>) then
                call TriggerExecute(Trigs<i>)
            endif
            set i=i+1
        endloop
endfunction

endlibrary</i></i></i>


The problem is that when I use DoStuff in trigger which has StuffEvent there will be an endless loop. Is there any simple way to make that DoStuff loop to ignore that trigger from which the triggering DoStuff was called...?
 

Romek

Super Moderator
Reaction score
963
JASS:
//
            if GetTriggeringTrigger() != Trigs<i> and IsTriggerEnabled(Trigs<i>) and TriggerEvaluate(Trigs<i>) then
                call TriggerExecute(Trigs<i>)
            endif</i></i></i></i>


Try that. Though I'm unsure of what'll happen if there is no TriggeringTrigger. :p
It might help to set GetTriggeringTrigger to a variable first, though I'm sure you knew to do that.
 

Viikuna

No Marlo no game.
Reaction score
265
Ok, I try and see if it bugs if there is no TriggeringTrigger. ( I think it just returns 0 or something )

Thanks for help.

edit. Works, I added a boolean argument registerSelf to DoStuff function, which can be used to stop endless loops.
 

Romek

Super Moderator
Reaction score
963
> I added a boolean argument registerSelf to DoStuff function, which can be used to stop endless loops.
JASS:
// -- Documentation: --
// boolean registerSelf:
// - Set this to true if you want to crash your map.

Are you sure that'd be needed? ^_^
 

Viikuna

No Marlo no game.
Reaction score
265
This system is just for my own use. I keep ithat boolean in case I want it to loop, maybe not endlessly, but for 5 or 10 times or something.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top