| 05-22-2008, 07:34 PM | #1 |
My Function:scope AnyTypeGroups //! textmacro Groups takes TYPE,NULL_TYPE,STRUCT_ARRAY,GROUP_ARRAY scope TBGroups$TYPE$ globals private integer Inc= 0 private integer Inc2= 0 s_$TYPE$Group GRP endglobals struct s_$TYPE$Group[$STRUCT_ARRAY$] private integer Index private integer array Copy[$GROUP_ARRAY$] private $TYPE$ array Group[$GROUP_ARRAY$] $TYPE$ Enum static method create takes nothing returns s_$TYPE$Group local s_$TYPE$Group s= s_$TYPE$Group.allocate() set s.Index=0 return s endmethod method add takes $TYPE$ t, boolean b returns nothing local integer i= .Index if b then loop exitwhen i==0 set i=i-1 if .Group[i]== t then return endif endloop set .Group[.Index]=t set .Index= .Index+1 else set .Group[.Index]=t set .Index= .Index+1 endif endmethod method remove takes $TYPE$ t, boolean b returns nothing local integer i= .Index if b then loop exitwhen i==0 set i=i-1 if .Group[i]== t then set .Copy[Inc]=i set Inc= Inc+1 endif if Inc>Inc2 then set Inc2=Inc endif loop exitwhen Inc== 0 set Inc= Inc-1 set .Index= .Index-1 set .Group[.Copy[Inc]]=.Group[.Index] set .Group[.Index]= $NULL_TYPE$ set .Copy[Inc]= 0 endloop endloop set Inc= 0 else loop exitwhen i==0 set i=i-1 if .Group[i]== t then set .Index= .Index-1 set .Group[i]=.Group[.Index] set .Group[.Index]= $NULL_TYPE$ return endif endloop endif endmethod method clear takes nothing returns nothing set .Index= 0 endmethod method clearAll takes nothing returns nothing loop exitwhen .Index== 0 set .Index= .Index-1 set .Group[.Index]=$NULL_TYPE$ endloop loop exitwhen Inc2== 0 set Inc2= Inc2-1 set .Copy[Inc2]= 0 endloop endmethod method isInGroup takes $TYPE$ t returns boolean local integer i= .Index loop exitwhen i== 0 set i= i-1 if t== .Group[i] then return true endif endloop return false endmethod method forGroup takes code c returns nothing local trigger t=CreateTrigger() local integer i= .Index local triggeraction act= TriggerAddAction(t,c) loop exitwhen i== 0 set i =i-1 set .Enum= .Group[i] set GRP= this call TriggerExecute(t) endloop call TriggerRemoveAction(t,act) call DestroyTrigger(t) set act= null set t= null endmethod endstruct endscope //! endtextmacro //! runtextmacro Groups("destructable","null","8190","100") endscope function LoopForGroup takes nothing returns nothing local s_destructableGroup s= GRP //call TriggerSleepAction(2.0)@ call BJDebugMsg( GetDestructableName(s.Enum)) endfunction function test takes nothing returns nothing local s_destructableGroup s= s_destructableGroup.create() call s.add(gg_dest_LTlt_0000,true) call s.add(gg_dest_LTba_0001,true) call s.add(gg_dest_LOcg_0002,true) call s.forGroup(function LoopForGroup) endfunction I don't understand why the function LoopForGroup is stopped when i use TriggerSleepAction ![]() PS: Dont care about the other code on the top, i will change it anyway |
| 05-22-2008, 07:48 PM | #2 |
ForGroup, ForForce, GroupEnum, EnumDestructables, etc... will all fail if you use TriggerSleepAction inside the callback. Has nothing to do with your code or vJASS. |
| 05-22-2008, 08:02 PM | #3 | |
Quote:
EDIT : it seems you can't use waits on a trigger action when you start it with TriggerExecute |
| 05-22-2008, 08:07 PM | #4 |
Yes. |
| 05-22-2008, 08:17 PM | #5 | |
Quote:
i tried this : JASS:function LoopForGroup takes nothing returns nothing local s_destructableGroup s= GRP call BJDebugMsg("begin") call TriggerSleepAction(1.0) call BJDebugMsg("end") call BJDebugMsg( GetDestructableName(s.Enum)) endfunction scope AnyTypeGroups //! textmacro Groups takes TYPE,NULL_TYPE,STRUCT_ARRAY,GROUP_ARRAY scope TBGroups$TYPE$ globals private integer Inc= 0 private integer Inc2= 0 s_$TYPE$Group GRP endglobals struct s_$TYPE$Group[$STRUCT_ARRAY$] private integer Index private integer array Copy[$GROUP_ARRAY$] private $TYPE$ array Group[$GROUP_ARRAY$] $TYPE$ Enum static method create takes nothing returns s_$TYPE$Group local s_$TYPE$Group s= s_$TYPE$Group.allocate() set s.Index=0 return s endmethod method add takes $TYPE$ t returns boolean local integer i= .Index if t== $NULL_TYPE$ then return false endif loop exitwhen i==0 set i=i-1 if .Group[i]== t then return false endif endloop set .Group[.Index]=t set .Index= .Index+1 return true endmethod method altAdd takes $TYPE$ t returns boolean local integer i= .Index if t== $NULL_TYPE$ then return false endif set .Group[.Index]=t set .Index= .Index+1 return true endmethod method remove takes $TYPE$ t, boolean b returns nothing local integer i= .Index if b then loop exitwhen i==0 set i=i-1 if .Group[i]== t then set .Copy[Inc]=i set Inc= Inc+1 endif if Inc>Inc2 then set Inc2=Inc endif loop exitwhen Inc== 0 set Inc= Inc-1 set .Index= .Index-1 set .Group[.Copy[Inc]]=.Group[.Index] set .Group[.Index]= $NULL_TYPE$ set .Copy[Inc]= 0 endloop endloop set Inc= 0 else loop exitwhen i==0 set i=i-1 if .Group[i]== t then set .Index= .Index-1 set .Group[i]=.Group[.Index] set .Group[.Index]= $NULL_TYPE$ return endif endloop endif endmethod method clear takes nothing returns nothing set .Index= 0 endmethod method clearAll takes nothing returns nothing loop exitwhen .Index== 0 set .Index= .Index-1 set .Group[.Index]=$NULL_TYPE$ endloop loop exitwhen Inc2== 0 set Inc2= Inc2-1 set .Copy[Inc2]= 0 endloop endmethod method isInGroup takes $TYPE$ t returns boolean local integer i= .Index loop exitwhen i== 0 set i= i-1 if t== .Group[i] then return true endif endloop return false endmethod method forGroup takes nothing returns nothing local trigger t=CreateTrigger() local integer i= .Index local triggeraction act= TriggerAddAction(t,function LoopForGroup) loop exitwhen i== 0 set i =i-1 set .Enum= .Group[i] set GRP= this call TriggerExecute(t) endloop call TriggerRemoveAction(t,act) call DestroyTrigger(t) set act= null set t= null endmethod endstruct endscope //! endtextmacro //! runtextmacro Groups("destructable","null","8190","100") endscope function test takes nothing returns nothing local s_destructableGroup s= s_destructableGroup.create() call s.add(gg_dest_LTlt_0000) call s.add(gg_dest_LTba_0001) call s.add(gg_dest_LOcg_0002) call s.forGroup() endfunction And it still doesn't work, i think it is cause of the TriggerExecute |
| 05-22-2008, 09:59 PM | #6 |
http://www.wc3campaigns.net/showthread.php?t=79029 ExecuteFunc could be used for this (unless you absolutely want to avoid this naitve) |
| 05-23-2008, 01:21 PM | #7 |
thank you, but I realize that the waits don't stack, so let's use timers and more and more functions ... |
