HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Looping through Destructables in a region/rectangle?

01-21-2006, 09:44 PM#1
agamemnus
How can I do this, at the risk of being lazy?

I want to take every destructable in a rectangle of type udg_treetype[udg_season_value] get some info from it, and remove it.

I've tried this:

Code:
function r3 takes destructable returns nothing
// I want to take each destructable in the rectangle and do stuff with it.. like remove it or get its properties for instance..
endfunction

function r2 takes nothing returns boolean
return ( GetDestructableTypeId(GetFilterDestructable()) == udg_treetype[udg_season_value])
endfunction


//... code at another spot:
EnumDestructablesInRect(rect1, r2, function r3)
//EnumDestructablesInRect rect r, boolexpr filter, code actionFunc 

Help......
01-21-2006, 10:04 PM#2
PitzerMike
Instead of function r3 you have to put Filter(function r3)

Or better use a filterfunc variable to avoid the leak.

local filterfunc f = Filter(function r3)

.....

DestroyFilter(f)
01-21-2006, 11:19 PM#3
agamemnus
I don't know how to reference the destructables either.
01-22-2006, 12:13 AM#4
agamemnus
HELP!
.....
01-22-2006, 01:41 AM#5
Vexorian
It is that you are too used to other language. The problem is that JASS is too messed up.

I don't know if I understand your "I don't know how to reference the destructables either." but I will see what I can do:

Collapse JASS:
function r3 takes destructable returns nothing
    call KillDestructable(GetEnumDestructable())
endfunction

function r2 takes nothing returns boolean
return ( GetDestructableTypeId(GetFilterDestructable()) == udg_treetype[udg_season_value])
endfunction


//... code at another spot:

local boolexpr B=Condition(function r2)
call EnumDestructablesInRect(rect1, B, function r3)
call DestroyBoolExpr(B)

01-22-2006, 01:55 AM#6
agamemnus
Thanks mate, works excellent. (except you copied "function r3 takes destructable returns nothing", should be "function r3 takes nothing returns nothing".)

>>I don't know how to reference the destructables either.
GetEnumDestructable()) is what I needed. :)
01-22-2006, 01:57 AM#7
Vexorian
certainly, I just modiffied your code and forgot about it
01-22-2006, 03:12 AM#8
agamemnus
Okay, now I have another problem.. I need to "write-protect" the trees...! Some trees under this system will grow and change seasons at the same time, fracking up the order... (because GetEnumDestructable() does not go in order but is an event)

It would be loads better if I could actually change how GetEnumDestructable() worked such that I could just load in the tree list...
01-22-2006, 01:15 PM#9
Vexorian
you could use the Enum to update an array and then use the array.

Now to avoid redoing something you could combine random numbers and gamecache, gamecache marks the last time a tree was updated and random numbers decide what trees to update.

Maybe you should use the Enum at the start just to fill the array and then stay using just the array