how to create an local group variable

Ashlebede

New Member
Reaction score
43
In JASS :

JASS:
local group myGroup


In GUI, you have to create a variable normally (CTRL+B), then you can create a local using Custom Script, with the same name as your variable pre-declared with CTRL+B. The local will have priority over the global when you use it :

Trigger:
  • Custom Script : local group udg_myGroupsName


Don't forget to place [ljass]udg_[/ljass] before your variable's name.

Note : it will not exist in your whole trigger, but only in the trigger's main function. It might not work as intended.
 

RangerX

I am justice!
Reaction score
69
well i know that but [this is my bad didn't put it straight] i need an variable in a jass spell :|

JASS:

function Trig_PA_GetG_II_Func003002002 takes nothing returns boolean
    return ( UnitHasBuffBJ(GetFilterUnit(), 'B007') == true )
endfunction

function Actions takes nothing returns nothing
    local group g
    local unit tu = GetEnumUnit()
    local location pos
    local location offpos
    set g = udg_Pulse_A
    set pos = GetUnitLoc(GetEnumUnit())
    set offpos = PolarProjectionBJ(pos, 150.00, ( 180.00 + GetUnitFacing(tu) ))
    call SetUnitPositionLoc( GetEnumUnit(), offpos )
    call RemoveLocation(pos)
    call RemoveLocation(offpos)
    call UnitRemoveAbility( tu, 'B007' )
    call GroupRemoveUnit( g,tu)
    call DestroyGroup (udg_Pulse_A)
endfunction

function Trig_PA_GetG_II_Actions takes nothing returns nothing
    local group g
    call TriggerSleepAction( 0.50 )
    set g = GetUnitsInRectMatching(GetPlayableMapRect(), Condition(function Trig_PA_GetG_II_Func003002002))
    call ForGroup( g, function Actions )
    call TriggerSleepAction( 0.10 )
    call DestroyGroup (g)
    set udg_Pulse_A = g
endfunction

//===========================================================================
function InitTrig_PA_GetG_II takes nothing returns nothing
    set gg_trg_PA_GetG_II = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_PA_GetG_II, 0.03 )
    call TriggerAddAction( gg_trg_PA_GetG_II, function Trig_PA_GetG_II_Actions )
endfunction


i need to get rid of that "udg_Pulse_A" thingy so i can be sure is mui :p
 

tooltiperror

Super Moderator
Reaction score
231
Despite what many coders think, boolexpr variables created through Condition or Filter do not leak any more than a string would, as they are recycled. When a boolexpr is first created, it is placed in the memory.

Actually, as the quote explains, [LJASS]boolexpr[/LJASS]'s are not created everytime you use [LJASS]Condition[/LJASS] or [LJASS]Filter[/LJASS], however they are created for the following functions.

JASS:

And(...,...)
Or(...,...)
Not(...)


You can also use [LJASS]null[/LJASS] in a boolexpr without leaking.
 

RangerX

I am justice!
Reaction score
69
is this the right way of doing this ?
JASS:

function filter takes nothing returns boolean
    return GetUnitAbilityLevel(GetFilterUnit(),'B007')>0
endfunction
function Main_Actions takes nothing returns nothing 
    local unit tu = GetEnumUnit()
    local location pos
    local location offpos
    local real angle
  if GetUnitAbilityLevel(tu,'B007')>0 then 
    set pos = GetUnitLoc(GetEnumUnit())
    set angle = AngleBetweenPoints(GetUnitLoc(GetTriggerUnit()), GetUnitLoc(tu)) 
    set offpos = PolarProjectionBJ(pos, 150.00, ( angle ) )
    call SetUnitPositionLoc( GetEnumUnit(), offpos )
    call RemoveLocation(pos)
    call RemoveLocation(offpos)
    call UnitRemoveAbility( tu, 'B007' )
  endif
endfunction

function Actions takes nothing returns nothing
    local group g = CreateGroup()
    local boolexpr be = Condition(function filter)
    call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea,be)
    call DestroyBoolExpr(be)
    call TriggerSleepAction(0.05)
    call ForGroup( g, function Main_Actions )
    call DestroyGroup (g)
endfunction



//===========================================================================
function InitTrig_PA_GetG_II takes nothing returns nothing
    set gg_trg_PA_GetG_II = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_PA_GetG_II, 0.03 )
    call TriggerAddAction( gg_trg_PA_GetG_II, function Actions )
endfunction
 

tooltiperror

Super Moderator
Reaction score
231
There are a few problems.

  • [LJASS]TriggerAddAction[/LJASS] is slower than [LJASS]TriggerAddCondition[/LJASS].
  • You make use of a few BJ's.
  • The Boolexpr doesn't need to be leak cleared like that, it's fine.
  • You are using leaking groups.
  • You don't need the filter function.
  • This should be in a scope/library.
 

RangerX

I am justice!
Reaction score
69
could you help me get this right I'm tring to learn jass
[without the BJ i know how to fix them but they are my last problem ]
 

tooltiperror

Super Moderator
Reaction score
231
JASS:
//warning: untested
 library Periodic initializer OnInit
   globals
       group GROUP=CreateGroup()
   endglobals
   private function filter takes nothing returns boolean
       local unit e = GetEnumUnit()
       local location pos
       local location offpos
       local real angle
       if GetUnitAbilityLevel(tu,'B007')>0 then 
           set pos = GetUnitLoc(GetEnumUnit())
           set angle = AngleBetweenPoints(GetUnitLoc(GetTriggerUnit()), GetUnitLoc(tu)) 
           set offpos = PolarProjectionBJ(pos, 150.00, ( angle ) )
           call SetUnitPositionLoc( GetEnumUnit(), offpos )
           call UnitRemoveAbility( tu, 'B007' )
       endif
       call RemoveLocation(pos)
       call RemoveLocation(offpos)
       set pos=null
       set offpos=null
       set e=null
       return false
   endfunction
   private function Actions takes nothing returns boolean
       call GroupEnumUnitsInRect(GROUP,bj_mapInitialPlayableArea,Filter(function filter))
       return false
   endfunction
   private function OnInit takes nothing returns nothing
       call TimerStart(CreateTimer(),0.05,true,function Actions)
   endfunction
 endlibrary


Completely untested, but it should work. Just remove the BJ's. I hope you know using a low frequency like this may cause lag.
 

RangerX

I am justice!
Reaction score
69
k testing :) i know but i use that just because the spell is an auto-attack spell [searing arrows] and i need it so the target go be pushed back [without using any slide cuz only in this is used knowkback :p let's see :p
 

tooltiperror

Super Moderator
Reaction score
231
If you just base your ability off of an existing one and use this library you can actually register the event.
 

RangerX

I am justice!
Reaction score
69
with the old trigger ? yes with this one they get the buff but it seems that the buff is not removed or instamove 150point backward
 

tooltiperror

Super Moderator
Reaction score
231
JASS:
//warning: untested
 library Periodic initializer OnInit
   globals
       group GROUP=CreateGroup()
   endglobals
   private function filter takes nothing returns boolean
       local unit e = GetEnumUnit()
       local location pos
       local location offpos
       local real angle
       if GetUnitAbilityLevel(tu,'B007')>0 then 
           set pos = GetUnitLoc(e)
           set angle = GetUnitFacing(e)+180
           set offpos = PolarProjectionBJ(pos, 150.00, ( angle ) )
           call SetUnitPositionLoc( GetEnumUnit(), offpos )
           call UnitRemoveAbility( tu, 'B007' )
       endif
       call RemoveLocation(pos)
       call RemoveLocation(offpos)
       set pos=null
       set offpos=null
       set e=null
       return false
   endfunction
   private function Actions takes nothing returns boolean
       call GroupEnumUnitsInRect(GROUP,bj_mapInitialPlayableArea,Filter(function filter))
       return false
   endfunction
   private function OnInit takes nothing returns nothing
       call TimerStart(CreateTimer(),0.05,true,function Actions)
   endfunction
 endlibrary


Should work now, I forgot that I separated the functions and didn't carry over a variable.
 
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