[vJass] Ordering ranged units in region to Hold Position

Carl-Fredrik

New Member
Reaction score
51
Ok, so I made this trigger to make ranged units in a region hold their positions:

JASS:
scope HoldPosition initializer HPInit

    globals
        private group GROUPPP
    endglobals

//==================================================
    private function HPGActions takes nothing returns nothing
        call IssueImmediateOrderBJ(GetEnumUnit(), "holdposition")
    endfunction

    private function HPConditions takes nothing returns boolean
        return IsUnitType(GetFilterUnit(), UNIT_TYPE_RANGED_ATTACKER)
    endfunction

    private function HPActions takes nothing returns nothing
        call GroupEnumUnitsInRect(GROUPPP, gg_rct_Region_003, Condition(function HPConditions))
        call ForGroup(GROUPPP, function HPGActions)
    endfunction

//====================================================================================================
    private function HPInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterTimerEvent(t, 1, false)
        call TriggerAddAction(t, function HPActions)
    endfunction

endscope


But for some reason it isn't working :( Does anyone know how to fix it?

Thanks in advance!
// Carl-Fredrik
 

Romek

Super Moderator
Reaction score
963
Your group isn't created.
set GROUPPP = CreateGroup() in your init function, or make that it's default value.
JASS:
    globals
  private group GROUPPP = CreateGroup()
endglobals


> return IsUnitType(GetFilterUnit(), UNIT_TYPE_RANGED_ATTACKER)
return IsUnitType(GetFilterUnit(), UNIT_TYPE_RANGED_ATTACKER) == true

IsUnitType can bug if not compared to true or false.

JASS:
        local trigger t = CreateTrigger()
        call TriggerRegisterTimerEvent(t, 1, false)
        call TriggerAddAction(t, function HPActions)

Could be:
JASS:
call TimerStart(CreateTimer(), 1., false, function HPActions)

But, that's not necessary for it to work.
 
Reaction score
91
> IsUnitType can bug if not compared to true or false.
And what kind of bug is it? It returns wrong boolean value?
 

No_exit

Regular User (What is Custom User Title?)
Reaction score
40

Carl-Fredrik

New Member
Reaction score
51
Your group isn't created.
set GROUPPP = CreateGroup() in your init function, or make that it's default value.
JASS:
    globals
  private group GROUPPP = CreateGroup()
endglobals


> return IsUnitType(GetFilterUnit(), UNIT_TYPE_RANGED_ATTACKER)
return IsUnitType(GetFilterUnit(), UNIT_TYPE_RANGED_ATTACKER) == true

IsUnitType can bug if not compared to true or false.

JASS:

        local trigger t = CreateTrigger()
        call TriggerRegisterTimerEvent(t, 1, false)
        call TriggerAddAction(t, function HPActions)

Could be:
JASS:
call TimerStart(CreateTimer(), 1., false, function HPActions)

But, that's not necessary for it to work.

Thanks! It works perfectly now :) +Rep if I can
 

Romek

Super Moderator
Reaction score
963
> And what kind of bug is it? It returns wrong boolean value?
Returns false when it should be true, so yes.

> With the current code, you will add all units in the group every time without removing them.
GroupEnum.. Clears the group.
Anyway, this'll only run once...
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top