| 04-15-2007, 08:21 AM | #1 |
Would like to know how do i loop over a struct type. (all structs of same type, since they are arrays) How do i get the max pointer (array index), and how do i know if a struct exist or is destroyed. Or do i have to create my own arrays to do this... |
| 04-15-2007, 01:43 PM | #2 |
no direct way. but you can make your structs enum cooperative: JASS:// if return true then it destroys it after evaluating . function interface booEnumFunction takes boo enumed returns boolean struct boo static boo array active static integer activen=0 private integer pos real t=2.0 static method create takes nothing returns boo local boo b=boo.allocate() set b.pos = boo.activen set boo.active[boo.activen]=b set boo.activen = boo.activen+1 return b endmethod private method onDestroy takes nothing returns nothing local boo last = boo.active[boo.activen-1] set boo.active[ this.pos ] = last set last.pos = this.pos set boo.activen=boo.activen-1 endmethod static method iterate takes booEnumFunction it returns nothing local integer i=0 loop exitwhen i>=boo.activen if (it.evaluate(boo.active[i] )) then call boo.active[i].destroy() else set i=i+1 endif endloop endmethod endstruct function ExampleIt takes boo enumed returns boolean // if x==0 then destroy it. if (enumed.x==0.) then return true endif return false endfunction function TestExampleIt takes nothing returns nothing call boo.iterate( booEnumFunction.ExampleIt ) endfunction |
| 04-15-2007, 04:10 PM | #3 |
hm... seems like i have to use my custom OO method... But thnx for help |
