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

[JASS] Local Handle Vars and GetHandleId

Status
Not open for further replies.
Level 14
Joined
Apr 20, 2009
Messages
1,543
Okay, so I know that Local Handle Vars are outdated.
But I was wondering how I would use an alternative?
(I do not want a vJass alternative, a global decleration block is not what I'm searching for)
I'm quite unfamillair with it and this is what I'm trying to do:

JASS:
function TimerFilter takes nothing returns nothing
    call QueueUnitAnimation(u, "spell")
endfunction

function Actions takes nothing returns nothing
    local unit u = CreateUnit(Player(0), 'hpea', 0, 0, 0)
    call SetUnitAnimation(u, "spell" )
    call TimerStart(CreateTimer(), 0.50, true, function TimerFilter)
endfunction

In this example, how would I get u inside the TimerFilter without using a global?
Also: how would I destroy the created timer after a specified amount of times being expired?
 
Last edited:
Well, with the hashtable method you only need 1 global for the hashtable. (the rest will just be saved within the function scope so you don't need globals for the members [unless you use struct-like attachment])

With unit indexing, you will need to make array variables for each thing you want to save, and you just need to make sure that you don't need to perform multiple instances of that code for the same unit. (otherwise data will be overwritten.. if that makes sense) Unit indexing should be faster attaching and receiving though, if I am not mistaken.

It depends on the trigger. It is up to you overall, but if you're not looking for speed then hashtables are usually the least cumbersome. :)
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
Thank you, this was exactly what I wanted to hear.
+rep

And yes the trigger needs to be MUI. So hashtables it is.
 
Dunno if you know but you could use this example of yours like this:
JASS:
function Actions takes nothing returns nothing
    local unit u = CreateUnit(Player(0), 'hpea', 0, 0, 0)
    call SetUnitAnimation(u, "spell" )
    call QueueUnitAnimation(u, "spell")
endfunction
and it will work fine, queued animation will be played after current one without any problems.
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
Dunno if you know but you could use this example of yours like this:
JASS:
function Actions takes nothing returns nothing
    local unit u = CreateUnit(Player(0), 'hpea', 0, 0, 0)
    call SetUnitAnimation(u, "spell" )
    call QueueUnitAnimation(u, "spell")
endfunction
and it will work fine, queued animation will be played after current one without any problems.

That is true, but I want it to wait 0.50 seconds and then queu the animation again. And I thought that using timers would be better then triggersleepaction since the trigger should be MUI and accurate.
This should be done 6 times in a row. I'm not exactly sure why, but I'm helping someone create a spell.

It's basically a pokeball that gets thrown.
The animation resets every 0.50 seconds or so, which makes it look as if the ball was having trouble catching the pokemon.
 
Here you go, sexy spell.
Using structs you can make this even more sexier :razz:
JASS:
library FailSpell initializer BitchPlease

    globals
        private string  ANIM_SEX       = /* o.O' */ "spell"
        private integer UNIT_SEX       = /*female*/ 'hmpr'
        private integer SEXY_SPELL     = 'AHtc'
        private real    SEXY_LOOP      = 0.5
        private real    SEXY_DURATION  = 5
        
        private hashtable SEXY_HASH = InitHashtable() //Because FUCK ME that's why
    endglobals

    private function UMad takes nothing returns nothing
        local timer t = GetExpiredTimer()
        local integer id = GetHandleId(t)
        local unit u = LoadUnitHandle(SEXY_HASH, id, 69)
        local real duration = LoadReal(SEXY_HASH, id, 666)
        if duration > 0 then
            call SetUnitAnimation(u, ANIM_SEX )
            call SaveReal(SEXY_HASH, id, 666, duration - SEXY_LOOP)
        else
            call PauseTimer(t)
            call DestroyTimer(t)
            call FlushChildHashtable(SEXY_HASH, id)
        endif
        set u = null /* Impossibru */
    endfunction

    function TheySeeMeRollinTheyHatin takes nothing returns boolean
        local unit  u
        local timer t
        //This line here is useless
        if GetSpellAbilityId() == SEXY_SPELL then
            set u = CreateUnit(GetTriggerPlayer(), UNIT_SEX, GetUnitX(GetTriggerUnit()), GetUnitY(GetTriggerUnit()), 0)
            call SetUnitAnimation(u, ANIM_SEX )
            set t = CreateTimer()
            call TimerStart(t, SEXY_LOOP, true, function UMad)
            call SaveUnitHandle(SEXY_HASH, GetHandleId(t), 69 , u)
            call SaveReal(      SEXY_HASH, GetHandleId(t), 666, 5)
            set u /* I like green, umad? */ = null
        endif
        return false
    endfunction

    private function BitchPlease takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
        loop
            call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
            set i = i + 1
            exitwhen i >12 // We can go to 666 if you want (well NOT)
        endloop
        call TriggerAddCondition(t, Condition( function TheySeeMeRollinTheyHatin ))
        set t = null
    endfunction

endlibrary
 

Attachments

  • aaa.w3x
    17.3 KB · Views: 50
Level 19
Joined
Aug 8, 2007
Messages
2,765
Can't u just save the unit under the handle of the timer than load the unit under the handle of expiring timer
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
didnt read your trigger, too long and too childish. you coulda just added a line of code to his original code
 
didnt read your trigger, too long and too childish. you coulda just added a line of code to his original code
Too long, please, what you expected 10 lines of code?
Using another libraries like table will short this code here, but in general it will be far more longer because of linked library. We speak about 1 spell not 10 different spells where table or other library from outside can actually short code in general.
And why is childish, after all it's not public resource, he can edit it easily?
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
Here you go, sexy spell.
Using structs you can make this even more sexier :razz:
JASS:
library FailSpell initializer BitchPlease

    globals
        private string  ANIM_SEX       = /* o.O' */ "spell"
        private integer UNIT_SEX       = /*female*/ 'hmpr'
        private integer SEXY_SPELL     = 'AHtc'
        private real    SEXY_LOOP      = 0.5
        private real    SEXY_DURATION  = 5
        
        private hashtable SEXY_HASH = InitHashtable() //Because FUCK ME that's why
    endglobals

    private function UMad takes nothing returns nothing
        local timer t = GetExpiredTimer()
        local integer id = GetHandleId(t)
        local unit u = LoadUnitHandle(SEXY_HASH, id, 69)
        local real duration = LoadReal(SEXY_HASH, id, 666)
        if duration > 0 then
            call SetUnitAnimation(u, ANIM_SEX )
            call SaveReal(SEXY_HASH, id, 666, duration - SEXY_LOOP)
        else
            call PauseTimer(t)
            call DestroyTimer(t)
            call FlushChildHashtable(SEXY_HASH, id)
        endif
        set u = null /* Impossibru */
    endfunction

    function TheySeeMeRollinTheyHatin takes nothing returns boolean
        local unit  u
        local timer t
        //This line here is useless
        if GetSpellAbilityId() == SEXY_SPELL then
            set u = CreateUnit(GetTriggerPlayer(), UNIT_SEX, GetUnitX(GetTriggerUnit()), GetUnitY(GetTriggerUnit()), 0)
            call SetUnitAnimation(u, ANIM_SEX )
            set t = CreateTimer()
            call TimerStart(t, SEXY_LOOP, true, function UMad)
            call SaveUnitHandle(SEXY_HASH, GetHandleId(t), 69 , u)
            call SaveReal(      SEXY_HASH, GetHandleId(t), 666, 5)
            set u /* I like green, umad? */ = null
        endif
        return false
    endfunction

    private function BitchPlease takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
        loop
            call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
            set i = i + 1
            exitwhen i >12 // We can go to 666 if you want (well NOT)
        endloop
        call TriggerAddCondition(t, Condition( function TheySeeMeRollinTheyHatin ))
        set t = null
    endfunction

endlibrary

Damn sexy indeed! Thank you good sir :D!
I can't rep you right now :(

Arhowk said:
too long and too childish.
Like a good friend of mine said: a dirty mind is a joy forever
 
Status
Not open for further replies.
Top