TriggerSleepAction() breaking Filter()?

Matrixboy

New Member
Reaction score
1
Hey there everyone!

I'm working on this one code, that would round up all the units owned by a single, and to kill them. This will be used when people leave, are kicked, etc. etc. I also have it running at Initialization, in-case slots aren't open. I have it display text that the player has left, or was never present, ping them, and then (should) wait 120.00 seconds and kill them.

This is what I currently have:

JASS:
library Funcs
    function remove takes nothing returns boolean
        local unit character = GetFilterUnit()
        local string name = GetUnitName(character)
        local integer y = 0
        call PingMinimap (GetUnitX(character), GetUnitY(character), 2.00)
        loop
            exitwhen y == 11
                call DisplayTextToPlayer(Player(y), 0.0, 0.0, "The owner of " + name + " has left the game.  His idle character has been pinged, and " + name + " will drop his items in 120 seconds, and die.")
                set y = y+1
        endloop
        call TriggerSleepAction(120.00)
        call KillUnit( character )
        set character = null
        return true
    endfunction
endlibrary


JASS:
function check_empty takes nothing returns nothing
    local group KillGroup = CreateGroup()
    local integer x = 0
    call TriggerSleepAction(0.00)

    loop
        exitwhen x==11
            if ( GetPlayerSlotState(Player(x)) != PLAYER_SLOT_STATE_PLAYING ) then
                call GroupEnumUnitsOfPlayer(KillGroup, Player(x), Filter(function remove))
            endif
            set x = x+1
    endloop
    set x = 0
    call DestroyGroup(KillGroup)
    set KillGroup = null
endfunction
//===========================================================================
function InitTrig_Init takes nothing returns nothing
    set gg_trg_Init = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Init, function check_empty )
endfunction


The only thing is, in the function remove, it seems to freeze at the TriggerSleepAction() call. After the alloted time, no character is killed. I've also done a test with simply printing text after the sleep, still to no avail. If I remove the call, it will work perfectly fine. But I really do wish to have the break between it, as to create a little interesting challenge for the corpses' items.

Would anyone know why it's doing this to me? I have a guess that it may have to be using it as the Filter in GroupEnumUnitsOfPlayer(), but have no way to test this (in all honesty, I don't know how any of the *Enum*() triggers work at all, so wouldn't know how to rewrite what I did. I posted here previously and someone graciously helped me out, however was unaware that I planned on adding the TriggerSleepAction() in. ).
 

Builder Bob

Live free or don't
Reaction score
249
I'm a little confused.

The only thing is, in the function remove, it seems to freeze at the TriggerSleepAction() call
Here you say there's a TriggerSleepAction() call in the function remove. In the code you posted the TriggerSleepAction() call is in the check_empty function.

As far as I can see the TriggerSleepAction() in the check_empty should not cause any problems.
However, if you tried using TriggerSleepAction() in the function remove, it would stop responding the way you describe it. This is because TriggerSleepAction() can only be used in Action functions. Not condition functions. Condition functions includes boolexpr, filter and conditionfunc.

If what you wrote was a typo, then I don't know what the problem is.
 

Matrixboy

New Member
Reaction score
1
I'm a little confused.


Here you say there's a TriggerSleepAction() call in the function remove. In the code you posted the TriggerSleepAction() call is in the check_empty function.

As far as I can see the TriggerSleepAction() in the check_empty should not cause any problems.
However, if you tried using TriggerSleepAction() in the function remove, it would stop responding the way you describe it. This is because TriggerSleepAction() can only be used in Action functions. Not condition functions. Condition functions includes boolexpr, filter and conditionfunc.

If what you wrote was a typo, then I don't know what the problem is.

Eek! Thank you for pointing that out. I did have TriggerSleepAction() in the function remove, however I posted the code I was testing (to see if it would work without it).

And thank you for explaining that it wouldn't work within Filter. That must have been why it wasn't working. Do you know of any way I can achieve what I'm attempting without filter? I never knew exactly what GroupEnum did anyways. Should I maybe make KillGroup a global, and pass all of the units owned by the missing player into that group?
 

Builder Bob

Live free or don't
Reaction score
249
Since you're using a library, I can see you have JassHelper. That will make solving this problem very simple.

Use this:
JASS:
library Funcs
    
    private function Enum takes nothing returns nothing
        local unit character = GetFilterUnit()
        local string name = GetUnitName(character)
        local integer y = 0
        call PingMinimap (GetUnitX(character), GetUnitY(character), 2.00)
        loop
            exitwhen y == 11
                call DisplayTextToPlayer(Player(y), 0.0, 0.0, "The owner of " + name + " has left the game.  His idle character has been pinged, and " + name + " will drop his items in 120 seconds, and die.")
                set y = y+1
        endloop
        call TriggerSleepAction(120.00)
        call KillUnit( character )
        set character = null
    endfunction
    
    function remove takes nothing returns boolean
        call Enum.execute()
        return true
    endfunction
endlibrary


By adding the extension .execute to a function call you can simulates an action function to allow you to use TriggerSleepAction().


Btw: You should start privatizing your functions (like I've done with the function Enum) so you can use the same function names in different scopes and libraries.
 

Matrixboy

New Member
Reaction score
1
Since you're using a library, I can see you have JassHelper. That will make solving this problem very simple.

Use this:
JASS:
....


By adding the extension .execute to a function call you can simulates an action function to allow you to use TriggerSleepAction().


Btw: You should start privatizing your functions (like I've done with the function Enum) so you can use the same function names in different scopes and libraries.

Thank you for all of your help! It works perfect now, thank you.

The .execute, that is working with it-as an object, correct? I was reading through the vjass manual, but most of it went right over my head. I never even noticed anything similar to what it said, and how you explained it. (I went back now, and did notice it mentioning something about execute, but in a lot more formal terms than you put it). Thanks for your explanation of it, made it a lot easier! I guess I'll have to go through and rad that manual again, if it'll help me avoid problems that make me bash my head against the wall.

Thanks, I just started putting everything into scopes, and privatizing things that I know won't be used outside of that library/scope. :p
 
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