• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Quick JASS question

Status
Not open for further replies.
Level 4
Joined
Jul 24, 2008
Messages
108
Ok, bare with me now. I am trying to write an AI function for one of the maps im making, I have had way to much trouble with desyncs and memory leaks using GUI so i have decided to convert all the problemed areas into jass to avoid this. One part of the trigger i am rewriting involves ordering a unit to attack another unit, which was defined by a variable. Here is the variable defining function

  • Find target
    • Events
    • Conditions
    • Actions
      • Set Kingstar = (Random unit from (Units in (Playable map area) matching (((Unit-type of (Matching unit)) Equal to A.P.C) or (((Unit-type of (Matching unit)) Equal to Getaway Car) or ((Unit-type of (Matching unit)) Equal to Runner)))))
Pretty simple, random unit of 3 different types of units. Now i learn by example so i converted it to jass to see what it looks like. Here is what i got


JASS:
function Trig_Find_target_Func001002001002001 takes nothing returns boolean
    return ( GetUnitTypeId(GetFilterUnit()) == 'hmtt' )
endfunction

function Trig_Find_target_Func001002001002002001 takes nothing returns boolean
    return ( GetUnitTypeId(GetFilterUnit()) == 'h000' )
endfunction

function Trig_Find_target_Func001002001002002002 takes nothing returns boolean
    return ( GetUnitTypeId(GetFilterUnit()) == 'uC01' )
endfunction

function Trig_Find_target_Func001002001002002 takes nothing returns boolean
    return GetBooleanOr( Trig_Find_target_Func001002001002002001(), Trig_Find_target_Func001002001002002002() )
endfunction

function Trig_Find_target_Func001002001002 takes nothing returns boolean
    return GetBooleanOr( Trig_Find_target_Func001002001002001(), Trig_Find_target_Func001002001002002() )
endfunction

function Trig_Find_target_Actions takes nothing returns nothing
    set udg_Kingstar = GroupPickRandomUnit(GetUnitsInRectMatching(GetPlayableMapRect(), Condition(function Trig_Find_target_Func001002001002)))
endfunction

//===========================================================================
function InitTrig_Find_target takes nothing returns nothing
    set gg_trg_Find_target = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Find_target, function Trig_Find_target_Actions )
endfunction


That is one giant mess and i do not want to have anything to do with that. From what i have learned so far, is the gui editor does conditions pretty poorly and inefficient. So now my question is can i combine all those into one with a function like this?

JASS:
return ( GetUnitTypeId(GetFilterUnit()) == 'hmtt' or 'h000' or 'uC01')

Or is that invalid? is there an easier way to pick any unit at random that is either 1 of 3 different units?
 
Level 4
Joined
Jul 24, 2008
Messages
108
<3 you redscores :)

You will become famous someday

EDIT

I wish life were easy...so that code didn't work how i thought it would so i decided to do something different and come up with something on my own, and it failed miserably. all i want is a unit group with 3 different types of units in them, all of them in the map. this is what i tried but WE yelled at me while saving

JASS:
    local group a = GetUnitsOfTypeIdAll('hmtt') 
    local group b = GetUnitsOfTypeIdAll('h000') 
    local group c = GetUnitsOfTypeIdAll('uC01') 
    local group enemies = group a + group b + group c
 
Last edited:
Level 7
Joined
Jul 20, 2008
Messages
377
JASS:
local group a = GetUnitsOfTypeIdAll('hmtt')
local group b = GetUnitsOfTypeIdAll('h000')
local group c = GetUnitsOfTypeIdAll('uC01')
local group enemy=CreateGroup()
call GroupAddGroup(a, enemy)
call GroupAddGroup(b, enemy)
call GroupAddGroup(c, enemy)

By the way, you should use JassCraft.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Those ways are both rather bad.

Just use the originally suggested filter, and skip the horrible inefficiency of doing a few times more calculations for the same end result.

Here's how you would establish the group:

JASS:
function FindTargetFilter takes nothing returns boolean
    return GetUnitTypeId(GetFilterUnit()) == 'hmtt' or GetUnitTypeId(GetFilterUnit()) == 'h000' or GetUnitTypeId(GetFilterUnit()) == 'uC01'
endfunction

function FindTarget takes nothing returns nothing
    local group g = CreateGroup()
    call GroupEnumUnitsInRect(g,bj_mapInitialPlayableArea,Filter(function FindTargetFilter))
    //use your group now.
    //Now, when you're done with your group
    call DestroyGroup(g)
    set g = null
endfunction

Or, if you really care about efficiency, you can use a global group and skip create/destroy/null.
 
Status
Not open for further replies.
Top