System TriggerGroups

Romek

Super Moderator
Reaction score
963
TriggerGroup Functions
By Romek

v1.1b

What is a triggergroup?
A triggergroup is something I created when making a map earlier today. I needed to disable a lot of triggers at 1 time, and thought of making some sort of system for it. Here is that system. (I also saw something similar in some wc3 extension called RTC)

A triggergroup is basically a group of triggers. 'Nough said. :p

The Functions:
JASS:
function CreateTriggerGroup takes nothing returns triggergroup

Simply creates a triggergroup for use.

JASS:
function DestroyTriggerGroup takes triggergroup tg returns nothing

Destroys a triggergroup to free up a slot (819 slots)

JASS:
function TriggerGroupAdd takes triggergroup tg, trigger t returns nothing

Adds a trigger to a triggergroup (Maximum of 200 per group)

JASS:
function TriggerGroupRemove takes triggergroup tg, trigger t returns nothing

Removes a trigger from a triggergroup

JASS:
function ClearTriggerGroup takes triggergroup tg returns nothing

Removes every trigger from a triggergroup

JASS:
function CountTriggersInTriggerGroup takes triggergroup tg returns integer

Counts the triggers in a triggergroup. Returns the amount as an integer.

JASS:
function ForTriggerGroupExecute takes triggergroup tg, string FuncName returns nothing

Executes a function (As a string (Remember to use the SCOPE_PRIVATE and SCOPE_PREFIX constants!)) for every trigger in the triggergroup

JASS:
function ForTriggerGroup takes triggergroup tg, code FuncName returns nothing

Runs a function for every trigger in the triggergroup.

JASS:
function GetEnumTrigger takes nothing returns trigger

Use in a "ForTriggerGroup" function to get the current trigger it's looping through.

JASS:
function FirstOfTriggerGroup takes triggergroup tg returns trigger

Gets the first trigger in the triggergroup.

JASS:
function RefreshTriggerGroup takes triggergroup tg returns nothing

A problem with triggergroups is that if a trigger is destroyed, and it is still in the group, it will become a null entry for the triggergroup and take up a slot.
This function simply removes all the null entries from a group.

JASS:
function TriggerGroupOrEvaluate takes triggergroup tg returns boolean

Returns true if at least 1 of the triggers evaluates true

JASS:
function TriggerGroupAndEvaluate takes triggergroup tg returns boolean

Returns true if all the triggers evaluate true



Extension Functions:
JASS:
function RunTriggerGroup takes triggergroup tg returns nothing

Runs every trigger in the triggergroup

JASS:
function DisableTriggerGroup takes triggergroup tg returns nothing

Disables every trigger in the triggergroup

JASS:
function EnableTriggerGroup takes triggergroup tg returns nothing

Enables every trigger in the triggergroup

JASS:
function ConditionalRunTriggerGroup takes triggergroup tg returns nothing

Runs the triggers in the group which evaluate true.

JASS:
function EvaluateTriggerGroup takes triggergroup tg returns nothing

Calls the condition of every trigger in the triggergroup

How to Use:
simply declare a local (or global) variable of type "triggergroup" and use it with the above functions :D
JASS:
local triggergroup TG = CreateTriggerGroup()


The Code:
JASS:
library TriggerGroups

    struct triggergroup [163820] // 819 * 200 (So 819 total groups, with up to 200 triggers in each)
        trigger array trig [200]
        integer total = 0
        
        method GET takes integer index returns trigger
            return .trig[index]
        endmethod
    
        static method create takes nothing returns triggergroup
            return triggergroup.allocate()
        endmethod
    endstruct
    
    globals
        private triggergroup Temp
        private integer index = 0
        private trigger callback = CreateTrigger()
    endglobals
    
    function TriggerGroupAdd takes triggergroup tg, trigger t returns nothing
        set tg.total = tg.total + 1
        if tg.total > 200 then
            set tg.total = tg.total - 1
            debug call BJDebugMsg("|cff995500TriggerGroup Error: No more space in TriggerGroup|r")
            return
        endif
        set tg.trig[tg.total] = t
    endfunction
    
    function FirstOfTriggerGroup takes triggergroup tg returns trigger
        return tg.trig[tg.total]
    endfunction
    
    function TriggerGroupRemove takes triggergroup tg, trigger t returns nothing
        local integer a = 0
        loop
            exitwhen a > tg.total
                if tg.trig[a] == t then
                    set tg.trig[a] = tg.trig[tg.total]
                    set tg.total = tg.total - 1
                    return
                endif
            set a = a + 1
        endloop
        debug call BJDebugMsg("|cff995500TriggerGroup Error: Attempt to remove a trigger not in group|r")
    endfunction

    // Creates the triggergroup for use
    function CreateTriggerGroup takes nothing returns triggergroup
        return triggergroup.create()
    endfunction
    
    // Used in ForTriggerGroup to get the current looping trigger
    function GetEnumTrigger takes nothing returns trigger
        return Temp.trig[index]
    endfunction
    
    // Counts how many triggers are in the triggergroup
    function CountTriggersInTriggerGroup takes triggergroup tg returns integer
        return tg.total
    endfunction 
    
    // Refreshes the triggergroup:
    //  - Removes null (destroyed) triggers from the triggergroup
    //  - sets the total to the correct amount
    function RefreshTriggerGroup takes triggergroup tg returns nothing
        local integer a = 0
        loop
            exitwhen a > tg.total
                if tg.trig[a] == null then
                    set tg.trig[a] = tg.trig[tg.total]
                    set a = a - 1
                    set tg.total = tg.total - 1
                endif
            set a = a + 1
        endloop
    endfunction
    
    // Clear the triggergroup
    function ClearTriggerGroup takes triggergroup tg returns nothing
        local integer a = 0
        loop
            exitwhen a > tg.total
                set tg.trig[a] = null
            set a = a + 1
        endloop
        set tg.total = 0
    endfunction
    
    // Destroys the triggergroup to free up a slot for another one.
    function DestroyTriggerGroup takes triggergroup tg returns nothing
        local integer a = 0
        loop
            exitwhen a > tg.total
                set tg.trig[a] = null
            set a = a + 1
        endloop
        set tg.total = 0       
        call tg.destroy()
    endfunction
    
    // Loop through every trigger in the triggergroup
    function ForTriggerGroupExecute takes triggergroup tg, string FuncName returns nothing
        local integer a = 0
        set Temp = tg
        loop
            exitwhen a > tg.total
                set index = a
                call ExecuteFunc(FuncName)
            set a = a + 1
        endloop
        set Temp = 0
        set index = 0
    endfunction
    
    // Loop through every trigger in the triggergroup
    function ForTriggerGroup takes triggergroup tg, code FuncName returns nothing
        local integer a = 0
        set Temp = tg
        call TriggerAddAction(callback, FuncName)
        loop
            exitwhen a > tg.total
                set index = a
                call TriggerExecute(callback)
            set a = a + 1
        endloop
        call TriggerClearActions(callback)
        set Temp = 0
        set index = 0
    endfunction
    
    // Returns the evaluation of all the triggers, only 1 has to be true.
    function TriggerGroupOrEvaluate takes triggergroup tg returns boolean
        local integer a = 0
        loop
            exitwhen a > tg.total
            if TriggerEvaluate(tg.trig[a]) then
                return true
            endif
            set a = a + 1
        endloop
        return false
    endfunction
    
    // Returns the evaluation of all the triggers, all of them have to be true.
    function TriggerGroupAndEvaluate takes triggergroup tg returns boolean
        local integer a = 0
        loop
            exitwhen a > tg.total
            if TriggerEvaluate(tg.trig[a]) == false then
                return false
            endif
            set a = a + 1
        endloop
        return true
    endfunction
endlibrary


The Extension:
These are basically some common tasks triggergroups will be used for made into a single function instead of requiring the user to use ForTriggerGroup(..)

How to Import:
Just add the code above the "endlibrary" in the main code.
JASS:
//   |======================|
//   |  E X T E N S I O N   |
//   |======================|  
    
    // Run every trigger in the group
    function RunTriggerGroup takes triggergroup tg returns nothing
        local integer a = 0
        loop
            exitwhen a > tg.total
            call TriggerExecute(tg.trig[a])
            set a = a + 1
        endloop
    endfunction
    
    // Evaluate every trigger in the group
    function EvaluateTriggerGroup takes triggergroup tg returns nothing
        local integer a = 0
        loop
            exitwhen a > tg.total
            call TriggerEvaluate(tg.trig[a])
            set a = a + 1
        endloop
    endfunction
    
    // Disable every trigger in the group
    function DisableTriggerGroup takes triggergroup tg returns nothing
        local integer a = 0
        loop
            exitwhen a > tg.total
            call DisableTrigger(tg.trig[a])
            set a = a + 1
        endloop
    endfunction
    
    // Enable every trigger in the group
    function EnableTriggerGroup takes triggergroup tg returns nothing
        local integer a = 0
        loop
            exitwhen a > tg.total
            call EnableTrigger(tg.trig[a])
            set a = a + 1
        endloop
    endfunction
    
    // Runs the triggers which evaluate true (Condition is true)
    function ConditionalRunTriggerGroup takes triggergroup tg returns nothing
        local integer a = 0
        loop
            exitwhen a > tg.total
            if TriggerEvaluate(tg.trig[a]) then
                call TriggerExecute(tg.trig[a])
            endif
            set a = a + 1
        endloop
    endfunction


Changelog:
Code:
V1.1b:
 - Changed the ForTriggerGroup function to take a code argument
 - Added a ForTriggerGroupExecute function (Which is the old ForTriggerGroup function)

V1.1:
 - Added some extra functions
 - Made DestroyTriggerGroup also clear the triggergroup.

V1.0:
 - Initial Release


A Demo Map:
Demonstrates most of the functions in this system :)
 

Blackgaze

New Member
Reaction score
0
I like the idea but the abilitity to turn triggers off is already enabled with the "turn off trigger", even with a large quantity of triggers activated at once the program itself won't cause any lags.

If you want to continue this idea do so, but it wouldn't be needed regardless. Oh and keep up the good coding.
 

Trollvottel

never aging title
Reaction score
262
i think it would be

JASS:

    function ForTriggerGroup takes triggergroup tg, code FuncName returns nothing
        local integer a = 0
        set Temp = tg
        loop
            exitwhen a > tg.total
                set index = a
                call FuncName()
            set a = a + 1
        endloop
        set Temp = 0
        set index = 0
    endfunction


example:

JASS:

call ForTriggerGroup( trg, function LoopTest)


if that doesnt work, add the code as triggeraction and execute the trigger, would be still faster than ExecuteFunc

btw, useful system.
 

PureOwnage

Minecraft Server OP, Inactive.
Reaction score
72
I like the idea but the abilitity to turn triggers off is already enabled with the "turn off trigger", even with a large quantity of triggers activated at once the program itself won't cause any lags.

If you want to continue this idea do so, but it wouldn't be needed regardless. Oh and keep up the good coding.
This is not for lag, it's for less coding of disabling triggers.
Also, if you needed to turn off a lot of triggers off, then it would have less coding necessary.
 

Flare

Stops copies me!
Reaction score
662
Hmmm - neat idea, but the reason behind it kinda confuses me. Either you manually <insert action here> all the triggers (just store them in an array and work from there?), or you create a trigger group, manually add them, then <some sort of action> them all at once... seems pretty much same effort for same result (even though triggergroup would be slightly longer, due to importing, creating the group, and a relatively long function call, vs. set trigz[count] = t -> set count = count + 1)

Also
JASS:
    // Destroys the triggergroup to free up a slot for another one.
    function DestroyTriggerGroup takes triggergroup tg returns nothing
        call tg.destroy()
    endfunction

It should also clear any existing triggers, otherwise
JASS:
function test takes nothing returns nothing
  local triggergroup tg = CreateTriggerGroup ()
  call TriggerGroupAdd (tg, someTrig)
  call DestroyTriggerGroup (tg)
  set tg = CreateTriggerGroup ()
  call RunTriggerGroup (tg) //Poo, we&#039;ve just used the trigger from the first instance of tg, since it&#039;s using the same struct instance I believe
endfunction

and a constant for maximum capacity would be nice (since people probably won't need 200 :p)

Also, perhaps a TriggerGroupEvaluate, and TriggerGroupAdd/RemoveTriggerGroup (equivalent to GroupAdd/RemoveGroup) would be of use

EDIT:
JASS:
    function GetFirstOfTriggerGroup takes triggergroup tg returns trigger
        return tg.trig[tg.total]
    endfunction

That'd be returning the last :p

And that GET method seems fairly useless (nothing is using it, and index is reset to 0 after the ForTriggerGroup, so it'd be the equivalent of GetFirst, assuming GetFirst actually retrieved the first :p)
 

Romek

Super Moderator
Reaction score
963
i think it would be

JASS:
    function ForTriggerGroup takes triggergroup tg, code FuncName returns nothing
        local integer a = 0
        set Temp = tg
        loop
            exitwhen a &gt; tg.total
                set index = a
                call FuncName()
            set a = a + 1
        endloop
        set Temp = 0
        set index = 0
    endfunction


example:

JASS:
call ForTriggerGroup( trg, function LoopTest)


if that doesnt work, add the code as triggeraction and execute the trigger, would be still faster than ExecuteFunc

btw, useful system.

Read the Note.
That would call a function that's under the function. So it would syntax :)

You are much better off using linked lists instead of arrays for this.

I don't even know what that is :p

Hmmm - neat idea, but the reason behind it kinda confuses me. Either you manually <insert action here> all the triggers (just store them in an array and work from there?), or you create a trigger group, manually add them, then <some sort of action> them all at once... seems pretty much same effort for same result
What if you can't use arrays? Say you're creating triggers in different functions, and making the triggergroup a global? :thup:

Also
JASS:
    // Destroys the triggergroup to free up a slot for another one.
    function DestroyTriggerGroup takes triggergroup tg returns nothing
        call tg.destroy()
    endfunction

It should also clear any existing triggers, otherwise
JASS:
function test takes nothing returns nothing
  local triggergroup tg = CreateTriggerGroup ()
  call TriggerGroupAdd (tg, someTrig)
  call DestroyTriggerGroup (tg)
  set tg = CreateTriggerGroup ()
  call RunTriggerGroup (tg) //Poo, we&#039;ve just used the trigger from the first instance of tg, since it&#039;s using the same struct instance I believe
endfunction

Forgot about that :)
Will add

and a constant for maximum capacity would be nice (since people probably won't need 200 :p)
my aim was to make it not need any configurations.
It's not hard to change the size if you want to anyway.

Also, perhaps a TriggerGroupEvaluate, and TriggerGroupAdd/RemoveTriggerGroup (equivalent to GroupAdd/RemoveGroup) would be of use

I'll add that in the future :)
(Correct me if I'm wrong: TriggerEvaluate just returns a boolean if the triggers condition is true / false.)

EDIT:
JASS:
    function GetFirstOfTriggerGroup takes triggergroup tg returns trigger
        return tg.trig[tg.total]
    endfunction

That'd be returning the last :p

Not like anyone will tell the difference anyway. :D
FirstOfGroup (for unit groups) could return the middle one for all we know.
Noone really needs the first one though :)
 

Flare

Stops copies me!
Reaction score
662
That would call a function that's under the function. So it would syntax
funcname.execute () ???

What if you can't use arrays?
For shame :p

Say you're creating triggers in different functions
Global, non-private trigger array

my aim was to make it not need any configurations.
One constant isn't exactly a gargantuan amount of configuration >_<

(Correct me if I'm wrong: TriggerEvaluate just returns a boolean if the triggers condition is true / false.)
Perhaps you could associate a boolexpr (since you can't have code arrays IIRC) with each trigger when adding (call TriggerGroupAdd (tg, trig, Condition (function AssociatedFunc)) then
JASS:
function TriggerGroupEvaluate takes triggergroup tg returns nothing
...
if TriggerEvaluate (a.trig<i>) then
  call a.assocFunc<i> () //Never really used boolexpr variables, so not sure how/if this would work, I think it can though
endif
...
endfunction</i></i>
 

Vestras

Retired
Reaction score
248
Very neat, I like.

Though, I think you would want the normal Blizz names for functions in the group and force sections, making it simpler to remember;

JASS:
function TriggerGroupAdd takes triggergroup tg, trigger t returns nothing


To;

JASS:
function TriggerGroupAddTrigger takes triggergroup tg, trigger t returns nothing


And,

JASS:
function ClearTriggerGroup takes triggergroup tg returns nothing


To;

JASS:
function TriggerGroupClear takes triggergroup tg returns nothing


And,

JASS:
function GetFirstOfTriggerGroup takes triggergroup tg returns trigger


To;

JASS:
function FirstOfTriggerGroup takes triggergroup tg returns trigger


Right? Well, about the string and code usage in ForTriggerGroup(...)...
Well, just do like this

JASS:
function ForTriggerGroup takes triggergroup tg, code callback returns nothing


And the code would look like:

JASS:
    function ForTriggerGroup takes triggergroup tg, code callback returns nothing
        local integer a = 0
        set Temp = tg
        loop
            exitwhen a &gt; tg.total
                set index = a
                call callback.execute()
            set a = a + 1
        endloop
        set Temp = 0
        set index = 0
    endfunction


I think that would work, but I got no compiler right now, test it.
+rep anyways.
 

Romek

Super Moderator
Reaction score
963
funcname.execute () ???
Gets a syntax. "FuncName is not of type that allowed . syntax"

Global, non-private trigger array
...Well, mappers choice. I think this is easier to use.

One constant isn't exactly a gargantuan amount of configuration >_<
But it's sill configuration ;)

Perhaps you could associate a boolexpr (since you can't have code arrays IIRC) with each trigger when adding (call TriggerGroupAdd (tg, trig, Condition (function AssociatedFunc)) then
JASS:
function TriggerGroupEvaluate takes triggergroup tg returns nothing
...
if TriggerEvaluate (a.trig<i>) then
  call a.assocFunc<i> () //Never really used boolexpr variables, so not sure how/if this would work, I think it can though
endif
...
endfunction</i></i>



I think I'm confused as to what exactly TriggerEvaluate does...
I have no idea what you're trying to do there :p

So far, I'm creating a TriggerGroupAndEvaluate, where all the triggers have to evaluate true, and TriggerGroupOrEvaluate, where only 1 needs to be true.

Edit I: I think I know what you where trying to do, make it only run the triggers which evaluate true (I think?).
I'll add something like this too :D

Edit II: Updated.
 

Flare

Stops copies me!
Reaction score
662
Gets a syntax. "FuncName is not of type that allowed . syntax"
Then you're screwed, because ExecuteFunc will be limited :p Anyway, if the function is 'available' when calling ForTriggerGroup, there shouldn't be any problem using it (even though a single function for execution is a bit crap :p) - just declare the function-to-be-called in a library :D

e.g.
JASS:
library summat initializer suminit
globals
 triggergroup tg
endglobals

private function suminit takes nothing returns nothing
  set tg = CreateTriggerGroup ()
endfunction

endlibrary

scope summatelse

function somefunc takes nothing returns nothing
...
endfunction

function start takes nothing returns nothing
call ForTriggerGroup (tg, function somefunc)
endfunction
endscope


...Well, mappers choice. I think this is easier to use.
If you add up all the effort, global array is shorter, typing-wise (and pretty much 0 function calls, so efficiency-wise also)

But it's sill configuration
No-one's gonna whine over 1 bit of configuration (if they do...)

I think I'm confused as to what exactly TriggerEvaluate does...
Checks if the trigger condition returns true or false (even though it's obviously of little use in some triggers, unless you're doing a system-'plausible' condition, that doesn't require an event, like GetRandomInt (1, 2) == 1)

I have no idea what you're trying to do there
If TriggerEvaluate (whichTrig) is true, call the associated boolexpr function (can't figure out how to call a boolexpr function variable, JASScraft is giving me errors :D) - will allot some bit of flexibility (since every trigger won't have to call the same function)

function TriggerGroupAddTrigger takes triggergroup tg, trigger t returns nothing
Too long :p You'd have to be stupid not to know what type you would add to a trigger group (lemme guess, is it a real? :p)
 

Romek

Super Moderator
Reaction score
963
Then you're screwed, because ExecuteFunc will be limited :p Anyway, if the function is 'available' when calling ForTriggerGroup, there shouldn't be any problem using it (even though a single function for execution is a bit crap :p) - just declare the function-to-be-called in a library :D

But this system is also a library. Unless the user made this library require the other one, it still wouldn't work (Or it would.. We don't know :p)

If you add up all the effort, global array is shorter, typing-wise (and pretty much 0 function calls, so efficiency-wise also)
:(

Checks if the trigger condition returns true or false (even though it's obviously of little use in some triggers, unless you're doing a system-'plausible' condition, that doesn't require an event, like GetRandomInt (1, 2) == 1)
So I was right :D

If TriggerEvaluate (whichTrig) is true, call the associated boolexpr function (can't figure out how to call a boolexpr function variable, JASScraft is giving me errors :D) - will allot some bit of flexibility (since every trigger won't have to call the same function)

Associated boolexpr.. Ever heard of the triggers actions? :p
Or you could just Evaluate the trigger which calls its condition :)
(Will add a function for that)

Too long :p You'd have to be stupid not to know what type you would add to a trigger group (lemme guess, is it a real? :p)
Agreed. Although I will change some of the other names :)
 

SerraAvenger

Cuz I can
Reaction score
234

Notes:
If anyone knows how to correctly use 'code' as an argument in the ForTriggerGroup function, let me know please :D


Just in case Vestras one shouldn't work:
Using a global constant trigger CALLBACK_TRIGGER,
and then do something like this:
JASS:
function ForTriggerGroup takes triggergroup tg, code callback returns nothing
    local integer a = 0
    call TriggerClearActions( CALLBACK_TRIGGER )
    call TriggerAddAction( CALLBACK_TRIGGER, callback )
    set Temp = tg
    loop
        exitwhen a &gt; tg.total
        set index = a
        call ExecuteTrigger( CALLBACK_TRIGGER )
        set a = a + 1
    endloop
    set Temp = 0
    set index = 0
endfunction


Anyway, great stuff. I had been using things like that since quite a long time, but without even thinking about making it a system. This really saves lots of work for me, I'll recode some of my systems to use it most probably : )

Also, this should take a boolean
JASS:

    // Disable every trigger in the group
    function DisableTriggerGroup takes triggergroup tg returns nothing
        local integer a = 0
        loop
            exitwhen a &gt; tg.total
            call DisableTrigger(tg.trig[a])
            set a = a + 1
        endloop
    endfunction
    
    // Enable every trigger in the group
    function EnableTriggerGroup takes triggergroup tg returns nothing
        local integer a = 0
        loop
            exitwhen a &gt; tg.total
            call EnableTrigger(tg.trig[a])
            set a = a + 1
        endloop


best regards, Davey​
 

Flare

Stops copies me!
Reaction score
662
But this system is also a library
>_> If the callback function is available, with regard to the position of the end-user's ForTriggerGroup, then there shouldn't be a problem - if you consider TT or ABCT, they wouldn't work either based on that same logic (since they are in libraries, and they take a code, I think, argument).

Order of functions only matters when calling the function (or using it as a parameter/storing it in a variable) - if it's accessible where you call/use as parameter/set to variable, then it should work.

(If I can figure out how to call a code variable, I can test it - did it once before, but can't seem to do it again xD)
 

Romek

Super Moderator
Reaction score
963
Just in case Vestras one shouldn't work:
Using a global constant trigger CALLBACK_TRIGGER,
and then do something like this:
JASS:
function ForTriggerGroup takes triggergroup tg, code callback returns nothing
    local integer a = 0
    call TriggerClearActions( CALLBACK_TRIGGER )
    call TriggerAddAction( CALLBACK_TRIGGER, callback )
    set Temp = tg
    loop
        exitwhen a &gt; tg.total
        set index = a
        call ExecuteTrigger( CALLBACK_TRIGGER )
        set a = a + 1
    endloop
    set Temp = 0
    set index = 0
endfunction

You can't add an action to a if the function is below the TriggerAddAction line.

Anyway, great stuff. I had been using things like that since quite a long time, but without even thinking about making it a system. This really saves lots of work for me, I'll recode some of my systems to use it most probably : )
Thanks :D

Also, this should take a boolean
JASS:
    // Disable every trigger in the group
    function DisableTriggerGroup takes triggergroup tg returns nothing
        local integer a = 0
        loop
            exitwhen a &gt; tg.total
            call DisableTrigger(tg.trig[a])
            set a = a + 1
        endloop
    endfunction
    
    // Enable every trigger in the group
    function EnableTriggerGroup takes triggergroup tg returns nothing
        local integer a = 0
        loop
            exitwhen a &gt; tg.total
            call EnableTrigger(tg.trig[a])
            set a = a + 1
        endloop

Why should that take a boolean? :nuts:

Thanks for the comments.

Edit: TriggerAddAction worked :D
Thanks everyone who helped there.
+Rep.
 

Flare

Stops copies me!
Reaction score
662
JASS:
scope AnotherTest initializer Init
globals
    private triggergroup tg
endglobals


private function foo2 takes nothing returns nothing

endfunction


private function foo1 takes nothing returns nothing
    call ForTriggerGroup (tg, function foo2)
endfunction


private function Init takes nothing returns nothing
    set tg = CreateTriggerGroup ()
endfunction
endscope

No syntax error (and foo2 isn't available to the library by itself :p) - since I couldn't figure out how to call a code variable, I just used TriggerAddAction

So, doesn't matter if the callback is available to the TriggerGroup library, as long as it's available to the line where you call ForTriggerGroup
 

Romek

Super Moderator
Reaction score
963
No syntax error (and foo2 isn't available to the library by itself :p) - since I couldn't figure out how to call a code variable, I just used TriggerAddAction

So, doesn't matter if the callback is available to the TriggerGroup library, as long as it's available to the line where you call ForTriggerGroup

I realised :D
I also used TriggerAddAction btw :)
 

Darius34

New Member
Reaction score
30
Hmm. In all honesty, I'm not sure I see how useful this is. Not saying it's useless, but it's a bit lacking in functionality as a real system.

Firstly, when would you need to execute triggers in large quantities (in what scenario, I mean)? The only one I can think of is when using dynamic triggers, and that's quite bad practice to begin with, due to all the potential bugs associated with DestroyTrigger(). There are lots of methods to work around using dynamic triggers, anyway. In other cases, the small number of triggers probably could be handled with an array and a counter variable.
 

SerraAvenger

Cuz I can
Reaction score
234
Why should that take a boolean? :nuts:
JASS:
function TriggerGroupEnable takes triggergroup tg, boolean enable returns nothing
  if enable then
    call TriggerGroup_Enable( tg )
  else
    call TriggerGroup_Disable( tg )
  endif
endfunction




EDIT:
Hmm. In all honesty, I'm not sure I see how useful this is. Not saying it's useless, but it's a bit lacking in functionality as a real system.

Firstly, when would you need to execute triggers in large quantities (in what scenario, I mean)?
Just when you're coding your own events, and then the TriggerRegister_OWN_Event( trigger t ) function just adds the trigger to the trigger group.

In other cases, the small number of triggers probably could be handled with an array and a counter variable.
Now you can either have 5 cases and for everyone you use an array with counter or a linked list, or you just import this stuff that does all that for you. +It has some cool features.

@ Romek:
Also, please do this with a linked list as Damien proposed. Would be really great :)
Just for the records:
You don't need your own create method if it doesn't but allocate.

JASS:
    struct triggergroup_trigger
        triggergroup_trigger NEXT
        trigger self
        static method create takes trigger self returns triggergroup_trigger
            local triggergroup_trigger this = .allocate()
            set .NEXT = 0
            set .self = self
            return this
        endmethod
    endstruct
        
    struct triggergroup [163820]
        triggergroup_trigger First
        integer total = 0
        
        method GET takes integer index returns trigger
            return .trig[index]
        endmethod
    
        static method create takes nothing returns triggergroup
            local triggergroup this = .allocate()
            set .First = 0
            return this
        endmethod
    endstruct

    function TriggerGroupAdd takes triggergroup tg, trigger t returns nothing
        local triggergroup_trigger this = tg.First
        if tg.total == 0 then
            set tg.First = triggergroup_trigger.create( t )
        else
            loop
                exitwhen .NEXT == 0
                set this = .NEXT
            endloop
            set .NEXT = triggergroup_trigger.create( t )
        endif
        set tg.total = tg.total + 1
    endfunction


and so on.
 

Darius34

New Member
Reaction score
30
Just when you're coding your own events, and then the TriggerRegister_OWN_Event( trigger t ) function just adds the trigger to the trigger group.
That function could just as easily add to an array.

Now you can either have 5 cases and for everyone you use an array with counter or a linked list, or you just import this stuff that does all that for you. +It has some cool features.
Meh, I don't think using an array would be that tedious. Plus, an array wouldn't require any function calls.

In any case, yeah, I guess a large merit of this system is the friendly, intuitive syntax it implements (just like the unit group vs unit array interface), which could be useful in a situation where large numbers of large arrays would be managed as the alternative.

@ Romek/Flare
Gets a syntax. "FuncName is not of type that allowed . syntax"
That should error - that's not how .execute() is used. .execute() and .evaluate() are used on function interfaces.

Maybe you'd want to switch to using function interfaces, Romek? Then you could make the trigger Enum function take arguments and remove the need for GetEnumTrigger() calls. It would all be less error-prone (no ExecuteFunc() crashes) and more friendly, not requiring users to use those scope prefixes.

Code:
function RefreshTriggerGroup takes triggergroup tg returns nothing
Requiring users to call this function seems like a bit of a regression, especially in a system that's supposed to automate things. Destroying dynamic triggers is bad practice anyway. Maybe the check could be omitted (unneeded), or done periodically?

Finally, why not make the extension code part of the system? Packaging it all together doesn't seem like a bad idea.
 
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