• 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] GetTriggerUnit and timers

Status
Not open for further replies.
Level 7
Joined
Mar 24, 2008
Messages
184
so, i wanted to try and make a spell in vJASS after reading some tutorials (i wanted to do that like 2-3 months ago but only now i have time since i'm done with uni exams) but i'm having some problems with timers

JASS:
library Shadowloop

   public function slicedice takes nothing returns nothing
        local loopthingie stru=GetUnitUserData(GetTriggerUnit())
        local unit SliceAndDiceCaster=stru.owner
        local unit SliceAndDiceTarget=stru.target
        //stuff
    endfunction
    
struct loopthingie
    public boolean attack=true
    public unit owner
    public unit target
    public timer loopy = CreateTimer()
    public integer in = 0
    public real angle1 
    public real angle2
    
    method onDestroy takes nothing returns nothing
        call PauseTimer(this.loopy)
        call DestroyTimer(this.loopy)
    endmethod

endstruct

private function Conditions takes nothing returns boolean
    return (GetSpellAbilityId() == 'A02O')== true
endfunction

private function Actions takes nothing returns nothing
    local loopthingie stru = GetUnitUserData(GetTriggerUnit())
    call TimerStart(stru.loopy, GetRandomReal(0.10, 0.27), true, function slicedice)
endfunction

//===========================================================================
public function InitTrig takes nothing returns nothing
    local trigger Shadowloop = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(Shadowloop, EVENT_PLAYER_UNIT_SPELL_CAST)
    call TriggerAddCondition(Shadowloop, Condition( function Conditions))
    call TriggerAddAction(Shadowloop, function Actions)
endfunction
endlibrary

The spell works this way, there's a unit that creates 4 clones and they all attack moving around the target, this is the part that's supposed to control each clone (the main spell puts the created unit and the target unit in the struct in the variables owner and target, and attaches it to the unit, then when it's needed, orders the units to use the ability to activate this trigger)
Actually i do know what the problem is, the GetTriggerUnit of the function slicedice doesn't get anything. i've tried passing the unit with a global variable and it worked, but i'm pretty sure there's a better way to do this, i just can't think anything to make it work (why oh why i can't use variables with arguments on timers code? there are some silly limits in the WE imho)
 
Last edited:
Level 7
Joined
Mar 24, 2008
Messages
184
So, i have to use Captain Griffen's Attach Timer function, very smart using the timer itself to move values, i wonder why i haven't thought of that :smile:

Still, using vJASS, there isn't any other way to do that? I mean, i feel like i'm missing something about structs
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
You can either use vJass or use the H2I bug which is a bit less stable and quite slower (in a programmers view).
An example for H2I usage is Katana's Handle Local Vars which I can't seem to find anymore in wc3c.

Of course there is always the ol' Game Cache if speed isn't important.
 
Level 7
Joined
Mar 24, 2008
Messages
184
i'm learning vJASS just because i've been told that it can do what Game Cache and Handle vars do (though i'm not sure of what theese two systems do, altough i read about them in many tutorials).
Well, i have time to learn, at least unitl september

I've seen the H2I function with the double return, it returns the handle id as integer if i got it right.

What i still don't understand (forgive me for my dumbness :cry: ) is what i have to do with vJASS, or at least if there's another way to do it other than the attach timer function (i haven't tried it yet, since i'm going out at the moment, but it's always better to know more than one way to do something, in case one doesn't work )
 
Status
Not open for further replies.
Top