| 05-05-2006, 04:59 AM | #1 |
I'm having difficulty setting a unit to a variable... What I mean is, I want to pick a unit that's in front of the Hero. When I do this in Jass, it keeps giving me an error on the Else line when using ForGroupBJ with no function calling at the end. Can someone give me a quick example of how to do this? |
| 05-05-2006, 05:28 AM | #2 |
Post the code. |
| 05-05-2006, 05:34 AM | #3 |
when using forgroup in jass you have to specify a boolexpr or you have to loop through the group. Lets say you want to collect udg_Bleh, which is a unit, into the group around the hero. First make a function, its just like a condition to match, to tell the script who to collect, it has to return a boolean: JASS:function CollectMatch takes nothing returns boolean return GetFilterUnit() == udg_Bleh endfunction You have to use GetFilterUnit() in boolexpressions and GetEnumUnit() in Group functions. You can also do something like: return IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) or any other condition. Now to collect: JASS:
local group g=CreateGroup()
local unit u = YOURUNIT
local boolexpr b = Condition(function CollectMatch)
call GroupEnumUnitsInRange(g, GetUnitX(u), GetUnitX(u), 400, b)
call ForGroup(g, function MyActions)
call DestroyGroup(g)
call DestroyBoolExpr(b)
set u=null
set b=null
set g=null
endfunction
What i did here was creating a boolexpr and then I used GroupEnumUnitsInRange(GROUP, X, Y, AreaOfEffect, BoolExpr) Its self explaining. The I used: call ForGroup(g, function MyActions) This is where you have to put another function to specify what you want to to do with the group. Example: JASS:function MyActions takes nothing returns nothing call KillUnit(GetEnumUnit()) endfunction Make sure to destroy Boolexpressions, if you dont they will leak. I'm not sure if you know this all or not, but I covered everything to make sure you'll understand, so dont be offended or something. |
| 05-05-2006, 11:16 AM | #4 |
Thanks much. |
