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

Problem with vJass

Status
Not open for further replies.
Level 3
Joined
Nov 28, 2008
Messages
24
Hi there, I'm currently learning vJass and was trying to code a simple dash spell. What the spell does is obvious: when cast, the casting unit dashes [int] units forward. This is the current code:

JASS:
scope Dash initializer Init
    private function Move takes nothing returns nothing
    //*This part is to move the unit forward every 0.03 seconds.
    //*I couldn't figure out how to retrieve the CastingUnit from
    //the private function 'Actions' and how can I stop the timer
    //when the unit reached its maximum range.
    //*I thought of declaring globals and use them but if I do so,
    //does that mean this spell is not MUI? Does this also mean that
    //if I use global variables, in order to make this spell MUI, I
    //would have to make an indexing system like in GUI?
    //*I also thought of using structs but I don't really understand
    //the concept of structs. If structs are much more easier, please
    //show me how to use them.
    endfunction
    
    private function Conditions takes nothing returns boolean
        return GetSpellAbilityId() == 'A000'
    endfunction
    
    private function Actions takes nothing returns nothing
        local unit a = GetSpellAbilityUnit()
        local timer b = CreateTimer()
        call TimerStart(b, 0.03, true, function Move)
        set a = null
    endfunction
    
    private function Init takes nothing returns nothing
        local trigger a = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(a, EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(a, Condition(function Conditions))
        call TriggerAddAction(a, function Actions)
    endfunction
endscope

Please explain it in simple english because I'm really bad at english. Thanks for helping.
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
You could use a global timer instead of creating a timer for each caster. Add the caster into a unit group. Then loop through the unit grouo.

You can take a look at my Punitive Surge spell, which is quite simple spell and does a similar thing as your spell is supposed to do.

I sould update the code a bit though for the sound part at least.
 
Level 3
Joined
Nov 28, 2008
Messages
24
You could use a global timer instead of creating a timer for each caster. Add the caster into a unit group. Then loop through the unit grouo.

You can take a look at my Punitive Surge spell, which is quite simple spell and does a similar thing as your spell is supposed to do.

I sould update the code a bit though for the sound part at least.

First of all, thanks for looking through the code.

I noticed in your spell, how you use 'Save/LoadReal / Save/LoadGroupHandle / Save/LoadBoolean' and 'StringHash'. What are those? What parameters exactly do they take? When I type 'SaveReal' in the trigger, it seems like an invalid native (not coloured in purple). Please explain.

Thanks again for helping out!
 
Status
Not open for further replies.
Top