• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[General] JASS What is the problem here?

Status
Not open for further replies.
Level 2
Joined
Jan 31, 2020
Messages
12
JASS:
scope CampLeave initializer init

globals
    private hashtable Data = InitHashtable()
    private trigger Trig = CreateTrigger()
    private integer Number = 0
    private rect array Area
endglobals

private function Set takes rect Leave returns nothing
    local region r = CreateRegion()
    set Number = Number + 1
    set Area[Number] = Leave
    call RegionAddRect(r, Leave)
    call TriggerRegisterLeaveRegion(Trig, r, null)
    call SaveInteger(Data, 0, GetHandleId(r), Number)
    call RemoveRect(Leave)
    set r = null
endfunction

private function Setting takes nothing returns nothing
    call Set(gg_rct_Test1)
    call Set(gg_rct_Test2)
    call Set(gg_rct_Test3)
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function GroupFilter takes nothing returns boolean
    return IsUnitType(GetEnumUnit(),UNIT_TYPE_HERO) == true and GetUnitState(GetEnumUnit(), UNIT_STATE_LIFE) > 0.405
endfunction

private function test takes nothing returns nothing
    local unit u
    local group g = CreateGroup()
    local integer n = LoadInteger(Data, 0, GetHandleId(GetTriggeringRegion()))
    call DisplayTextToForce( GetPlayersAll(), "test" )
    call GroupEnumUnitsInRect(g, Area[n], Condition(function GroupFilter))
    call DisplayTextToForce( GetPlayersAll(), I2S(CountUnitsInGroup(g)) )
    loop
        call DisplayTextToForce( GetPlayersAll(), "grouploop1" )
        set u = FirstOfGroup(g)
        exitwhen u == null
        call DisplayTextToForce( GetPlayersAll(), "grouploop2" )
        call GroupRemoveUnit(g,u)
    endloop
    call DestroyGroup(g)
    set g = null
endfunction

private function CampLeave takes nothing returns nothing
    local timer time = CreateTimer()
    call DisplayTextToForce( GetPlayersAll(), "func" )
    if IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == true and IsUnitEnemy(GetTriggerUnit(), Player(0)) == false then
        call DisplayTextToForce( GetPlayersAll(), "if" )
        call TimerStart(time, 3.0, false, function test)
    endif
    set time = null
endfunction

private function init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterTimerEvent(t, 0.01, false)
    call TriggerAddAction(t, function Setting)
    call TriggerAddAction(Trig, function CampLeave)
    set t = null
endfunction

endscope

I am sorry I don't know how to write code.
I am trying to make some triggers with jass.

I want it to be worked like this:
when a hero that is ally of player1 gets out of Test1, Test2, Test3,
I want to do some work on alive heroes left in the area where a hero left.

But somehow I never get any heroes in group g.
and is this leak safe?
I am using DisplayTextToForce to checking where the problem is.

And one more question, what is the difference between Filter and Condition?

Thanks
 
Last edited:
Level 7
Joined
Apr 17, 2017
Messages
316
First of all there is no difference between Condition and Filter. However it's a common approach to use Condition for trigger Conditions and Filter for enumerations.
Inside your Filter function, replace GetEnumUnit() with GetFilterUnit(). Also use
JASS:
 native UnitAlive takes unit u returns boolean
to check if a unit is alive.
 
Level 2
Joined
Jan 31, 2020
Messages
12
Thank you.
I will try when I go home back.
Btw how do I make codes to be in code block just like you and all others do?
Mine is just plain text.
 
Status
Not open for further replies.
Top