• 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.

[vJASS] [AutoIndex] Doing actions on Deindex

Status
Not open for further replies.
Level 14
Joined
Jul 26, 2008
Messages
1,009
Alright so I'm using AutoIndex (It's what works with 90% of my systems) and I want to be able to flush all the saved attachments on a unit when the unit is deindex.

Unfortunately, I don't know how to do that, being a bit unfamiliar with fully using the system. This is my attempt. Any help?

JASS:
function Trig_Flush_Attachments_Actions takes nothing returns nothing
 local integer i = 0
    loop
    exitwhen i == 10
        call DestroyEffect(LoadEffectHandle(QuestTable, i, GetHandleId(GetTriggerUnit())))
        call FlushChildHashtable(QuestTable, i)
     set i = i + 1
    endloop
endfunction

//===========================================================================
function InitTrig_Flush_Attachments_On_Death takes nothing returns nothing
    //set gg_trg_Flush_Attachments_On_Death = CreateTrigger(  )
    //call TriggerRegisterAnyUnitEventBJ( gg_trg_Flush_Attachments_On_Death, EVENT_PLAYER_UNIT_DEATH )
    //call TriggerAddAction( gg_trg_Flush_Attachments_On_Death, function Trig_Flush_Attachments_Actions )
    call OnUnitDeindexed(Trig_Flush_Attachments_Actions)
endfunction

Also, on a side note, is there a way to detect when a unit is removed from the map with a Timer (TimerUtils) going on them? This would help me greatly.
 
Last edited:
The function must take a unit and return nothing. So in your case:
JASS:
function Trig_Flush_Attachments_Actions takes unit u returns nothing
 local integer i = 0
    loop
    exitwhen i == 10
        call DestroyEffect(LoadEffectHandle(QuestTable, i, GetHandleId(GetTriggerUnit())))
        call FlushChildHashtable(QuestTable, i)
     set i = i + 1
    endloop
endfunction

function InitTrig_Flush_Attachments_On_Death takes nothing returns nothing
    call OnUnitDeindexed(Trig_Flush_Attachments_Actions)
endfunction

For your side note, I don't think AutoIndex does anything publicly-accessible to let you know if a unit is removed. By removed, do you mean removed via RemoveUnit or do you mean when a unit is deindexed in general?

One solution that I recommend is to just create a boolean array whenever a unit is deindexed:
JASS:
scope FlagWhenDeindexed initializer Init
    globals
        boolean array isUnitDeindexed // boolean arrays will default false
    endglobals

    private function SetFlag takes unit u returns nothing
        set isUnitDeindexed[GetUnitUserData(u)] = true
    endfunction

    private function Init takes nothing returns nothing
        call OnUnitDeindexed(SetFlag)
    endfunction
endscope

That way, in your timer functions you can simply do a check if isUnitDeindexed then then just break out/destroy all stuff. Good luck.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Ok... I'm not that good with jass and system dephts but...

native FlushChildHashtable takes hashtable table, integer parentKey returns nothing

are i (1->10) your parentkeys?

Shouldn't it be call DestroyEffect(LoadEffectHandle(QuestTable, GetHandleId(GetTriggerUnit(), i)))?

FlushChildHashtable(QuestTable, i) would flush Hashtable parentkeys from 1 to 10... I think what you want is FlushChildHashtable(QuestTable, GetHandleId(GetTriggerUnit()) to clear the data stored in the UnitID, and that would be just once, not 10 times in a loop.

I've always used "A unit dies" to clear Unit hash data since I've never planned to revive them... You could use "A unit decays" event.
 
Level 14
Joined
Jul 26, 2008
Messages
1,009
I removed the Flush. Realized I wasn't 100% sure it was doing what I figured it was, or really that I knew what it was doing in general the way it was behaving.

I'm mainly concerned with RemoveUnit commands moreso than general Deindexing when it comes to stopping the effects of TimerUtils. I figure that two have some similarities that I can exploit to stop a timer, but there's not a lot of "RemoveUnit" commands so it could be useful to do the solution like you said but in the RemoveUnit commands.
I'll check to see if I still get DoubleFrees on just UnitRemove or if it's on unit decay as well.
 
Level 14
Joined
Jul 26, 2008
Messages
1,009
Just a realization Purge, and correct me if I'm wrong, but wouldn't calling a unit that's been DeIndexed be rather impossible? If the unit is Deindexed, then the unit is null. How do you check a null unit to see if it's been Deindexed? (I know the DeIndex is called just before the unit is removed from the map)
 
Oops, yeah you are probably right. I haven't tested it. In that case, you can just check if the unit == null, right? If it is null, then you can break out of the timer. That should work in theory, but I don't exactly remember what happens when you reference a removed unit.

It is still worth a shot though, as that would most likely be the easiest solution.
 
Status
Not open for further replies.
Top