• 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] Help with these functions

Status
Not open for further replies.
Level 4
Joined
Jul 24, 2008
Messages
108
I feel like i've been asking a lot from you guys recently, but im trying to learn jass and so far these functions i wrote have no errors in them but i cannot figure out why it doesn't work. Here is what is suppost to happen in plain english, a few seconds into the game it will choose a target that is a random unit of all the units of 3 different types. It sets this to a variable, now when some super unit comes along, it will bascially order him to keep attacking the location of that unit until he dies. Once he dies, it willl run the findtarget function again to get a new one and chase that guy down until he dies. For testing purposes, i just created a gui trigger that sets the global unit that is doing the attacking to a preplaced unit ( in game it will be spawned towards the end of the game)

  • Debug
    • Events
      • Time - Elapsed game time is 1.00 seconds
    • Conditions
    • Actions
      • Set king = |c00330033King Kodo 0035 <gen>
Now in my map initiation section where i can put just custom scripts i have


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

function settarget takes nothing returns unit
    local group g = CreateGroup()
    local unit u
    call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea,Filter(function FindTargetFilter))
    set u = GroupPickRandomUnit(g)
    set udg_Kingstar = u
    set u = null
    set g = null
    return udg_Kingstar
endfunction

this is where it puts the units that it will potentially choose into a group, then choose a random one, and destroy the group. It willl be called in the first second of the game (testing purposes) and will also be called again when the unit it returns dies. (not made yet). Trigger to run this the first time

JASS:
function InitTrig_firsttarget takes nothing returns nothing
    set gg_trg_firsttarget = CreateTrigger()
    //call TriggerRegister__(gg_trg_NewTrigger, )
    call TriggerRegisterTimerEventSingle( gg_trg_firsttarget , 3.00 )
    call TriggerAddAction(gg_trg_firsttarget, function settarget)
endfunction


Now for the actual ordering part of this. Here is the trigger. It finds the location of the previously found target and orders the attacking unit to attack position of its target every few seconds. the udg_king is already defined through gui above for testing purposes


JASS:
function kingsattack takes nothing returns nothing
    local location loc     
    set loc = GetUnitLoc(udg_Kingstar)
    call IssuePointOrderLocBJ(udg_king , "attack" , loc )
    call RemoveLocation(loc)
    set loc = null
endfunction

function InitTrig_kingsai takes nothing returns nothing
    set gg_trg_attacktrig = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_kingsai , 5.00 )
    call TriggerAddAction( gg_trg_kingsai, function kingsattack )
endfunction

When i test it, i get no errors and it works. Now once im in game, nothing happens. Is there some really stupid mistake i made?
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
JASS:
    set u = GroupPickRandomUnit(g)
    set udg_Kingstar = u
This can be merged into
set udg_Kingstar = GroupPickRandomUnit(g)
to remove the need for a u unit variable.
function settarget also leaks a group

What you could also add to the filter is a check if the filter unit is still alive. Other than that I don't see anything bad. If the problem persists, I suggest you to add debugmessages, for instance check if udg_kingstar (the target unit) is null, then print a debugmessage so you know for some reason there is no target.
 
Level 4
Joined
Jul 24, 2008
Messages
108
Ok, problem is fixed however it doesn't make sense on how it was fixed. So my question now is what is the difference between

JASS:
    call IssuePointOrderLoc(udg_king , "attack" , loc )

and

    call IssuePointOrderLocBJ(udg_king , "attack" , loc )

because that seemed to fix it. How does settarget leak? Is it fixed in this code?

JASS:
function settarget takes nothing returns unit
    local group g = CreateGroup()   
    call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea,Filter(function FindTargetFilter))
    set udg_Kingstar = GroupPickRandomUnit(g)
    set g = null
//    call BJDebugMsg (GetUnitName(udg_Kingstar))
    return udg_Kingstar
endfunction

I have nulled g.


---EDIT---

Ok, im not that old but i cannot seem to see the difference between these 2 funcitons. One i just made in gui and converted to custom text, the other i made my self, they seem to be the exact same thing however one works and one doesn't.

JASS:
function kingsattack takes nothing returns nothing   
    call IssuePointOrderLocBJ( udg_king, "attack", GetUnitLoc(udg_Kingstar) )
    call BJDebugMsg (GetUnitName(udg_king))
endfunction

function InitTrig_kingsai takes nothing returns nothing
    set gg_trg_attacktrig = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_kingsai , 5.00 )
    call TriggerAddAction( gg_trg_kingsai, function kingsattack )
endfunction
I made that one

now this one is the one from blizzard and it works fine

JASS:
function Trig_Orders_K_Actions takes nothing returns nothing
    call IssuePointOrderLocBJ( udg_king, "attack", GetUnitLoc(udg_Kingstar) )
    call BJDebugMsg (GetUnitName(udg_king))
endfunction

//===========================================================================
function InitTrig_Orders_K takes nothing returns nothing
    set gg_trg_Orders_K = CreateTrigger(  )
   
    call TriggerRegisterTimerEventPeriodic( gg_trg_Orders_K, 5.00 )
    call TriggerAddAction( gg_trg_Orders_K, function Trig_Orders_K_Actions )
endfunction
I did however add the debug to the blizzards
 
Last edited:
Level 7
Joined
Jul 20, 2008
Messages
377
This is what IssuePointOrderLocBJ does:

JASS:
function IssuePointOrderLocBJ takes unit whichUnit, string order, location whichLocation returns boolean
    return IssuePointOrderLoc( whichUnit, order, whichLocation )
endfunction

So I don't know why it's not working.
 
Status
Not open for further replies.
Top