So, I've come across an interesting theory, and I was wondering if it can be executed.
What if you want to get a random unit in a group inside struct A, then place that random unit in a unit variable in struct A?
I tried this but, the Forgroup doesn't take the word method for function, so is there any approach for this?
Using function as method in a struct is not allowed! so don't try giving me an evasive answer
Maybe there's another way of getting a unit in a group?
Since it's hard explaining with words, let's just look at my code (doesn't compile because I use the word Method not Function)
Don't mind the textmacro, for some reason, the [ jass ] text acts oddly
EDIT: after some testing, and some native search, I found that FirstOfGroup(group) takes care of my problem, if I only need one target, but the question remains.
Is it possible to use a Forgroup in a struct?
EDIT: also, filters?
don't know how to add a filter either, here's the new code
EDIT: Wow, lots of edits... sorry about that, I tested to use a conditional function outside the struct, and obviously that worked, but since i need the unit member inside the struct... Can you attach handles to a condition?
Anyway, the forgroup issue stated earlier. The filter can be applied outside of the struct, but the forgroup callback uses a struct member, so is there a way?
What if you want to get a random unit in a group inside struct A, then place that random unit in a unit variable in struct A?
I tried this but, the Forgroup doesn't take the word method for function, so is there any approach for this?
Using function as method in a struct is not allowed! so don't try giving me an evasive answer
Maybe there's another way of getting a unit in a group?
Since it's hard explaining with words, let's just look at my code (doesn't compile because I use the word Method not Function)
JASS:
struct dat
integer speed = 40
unit target
unit spawn
unit caster
group randomunit = CreateGroup()
boolean go = false
//! textmacro spawnmethod takes MOD
method Spawn$MOD$ takes nothing returns real
return GetModified$MOD$( GetUnitX(this.spawn), GetUnitY(this.spawn), GetUnitX(this.target), GetUnitY(this.target) )
endmethod
//! endtextmacro
//! runtextmacro spawnmethod("Dist")
//! runtextmacro spawnmethod("Angle")
method SpawnMove takes nothing returns nothing
local real x = GetUnitX(this.spawn)+this.speed*Cos(this.SpawnAngle()* bj_DEGTORAD)
local real y = GetUnitY(this.spawn)+this.speed*Sin(this.SpawnAngle()* bj_DEGTORAD)
call SetUnitX(this.spawn, x)
call SetUnitY(this.spawn, y)
endmethod
//Getting random unit enum
method newtarget takes nothing returns nothing
set this.target = GetEnumUnit()
endmethod
//Get random unit
method GetNewTarget takes nothing returns nothing
//get some group within range or something and then get the random unit
call GetRandomSubGroup( 1, this.randomunit)
//and lets assing target = random unit
call Forgroup(this.randomunit, method newtarget )
endmethod
endstruct
EDIT: after some testing, and some native search, I found that FirstOfGroup(group) takes care of my problem, if I only need one target, but the question remains.
Is it possible to use a Forgroup in a struct?
EDIT: also, filters?
don't know how to add a filter either, here's the new code
JASS:
struct dat
integer speed = 40 //
unit target //
unit spawn
unit caster
boolean go = false
//! textmacro spawnmethod takes MOD
method Spawn$MOD$ takes nothing returns real
return GetModified$MOD$( GetUnitX(this.spawn), GetUnitY(this.spawn), GetUnitX(this.target), GetUnitY(this.target) )
endmethod //
//! endtextmacro
//! runtextmacro spawnmethod("Dist")
//! runtextmacro spawnmethod("Angle")
method SpawnMove takes nothing returns nothing
local real x = GetUnitX(this.spawn)+this.speed*Cos(this.SpawnAngle()* bj_DEGTORAD)
local real y = GetUnitY(this.spawn)+this.speed*Sin(this.SpawnAngle()* bj_DEGTORAD)
call SetUnitX(this.spawn, x)
call SetUnitY(this.spawn, y)
endmethod
method GetNewTarget takes nothing returns unit
local group tempg = CreateGroup()
call GroupEnumUnitsInRange(tempg, GetUnitX(this.spawn), GetUnitY(this.spawn), 1000, Condition(method?) )
call GetRandomSubGroup( 1, tempg)
return FirstOfGroup(tempg)
endmethod
endstruct
EDIT: Wow, lots of edits... sorry about that, I tested to use a conditional function outside the struct, and obviously that worked, but since i need the unit member inside the struct... Can you attach handles to a condition?
Anyway, the forgroup issue stated earlier. The filter can be applied outside of the struct, but the forgroup callback uses a struct member, so is there a way?
Last edited: