Vjass Spell not working

l1lshadow

New Member
Reaction score
4
Hello, I haven't coded JASS in about a year and I recently read a VJASS tutorial, but the spell I made (not based on the tutorial) doesn't work. I am not looking to optimize my spell yet, I am just trying to find out what the problem is, its supposed to shoot out a missile toward a point. The problem is that it only creates the dummy unit though and doesn't move :
JASS:
scope Projectile initializer Init

    globals
        private constant integer SPELL_ID = 'A000'
        private constant integer SPEED = 900
        private constant real RANGE = 600.00
        real CRANGE = 0.00
        projectiledata array Projectile_Ar
        timer Projectile_timer = CreateTimer()
    endglobals
    
    constant function Projectile_Dummy takes nothing returns integer
        return 'h001'
    endfunction
    
    struct projectiledata
        unit d
        location l
        real x
        real y
    endstruct
    
    function Conditions takes nothing returns boolean
        return GetSpellAbilityId() == SPELL_ID
    endfunction
    
    function Timer takes nothing returns nothing
        local projectiledata dat
        local real angle
        local real nx
        local real ny
        
            if (CRANGE == 600.00) then
                call dat.destroy()
                call RemoveUnit(dat.d)
                call PauseTimer(Projectile_timer)
            else
                set angle = bj_RADTODEG * Atan2(GetLocationY(dat.l) - GetUnitY(dat.d), GetLocationX(dat.l) - GetUnitX(dat.d))
                set nx = GetUnitX(dat.d) + 10.00 * Cos(angle * bj_DEGTORAD)
                set ny = GetUnitY(dat.d) + 10.00 * Sin(angle * bj_DEGTORAD)
                call SetUnitPosition(dat.d, nx, ny )
                set CRANGE = CRANGE + 10.00
            endif
            
    endfunction
    
    function Actions takes nothing returns nothing
        local unit b = GetTriggerUnit()
        local unit d = CreateUnit(GetOwningPlayer(b), Projectile_Dummy(), GetUnitX(b), GetUnitY(b), 90.00)
        local location l = GetSpellTargetLoc()
        local projectiledata dat = projectiledata.create()
            set dat.x = 0.00
            set dat.y = 0.00
            set dat.d = d
            set dat.l = l
            call TimerStart(Projectile_timer, 0.01, true, function Timer)
    endfunction


    private function Init takes nothing returns nothing
        local trigger ProjectileTrg = CreateTrigger(  )
        call TriggerRegisterAnyUnitEventBJ(ProjectileTrg, EVENT_PLAYER_UNIT_SPELL_EFFECT )
        call TriggerAddCondition( ProjectileTrg, Condition(function Conditions) )
        call TriggerAddAction( ProjectileTrg, function Actions )
        
    endfunction

endscope
 

Laiev

Hey Listen!!
Reaction score
188
what i say to you is to do something like this:

JASS:
    private function Timer takes nothing returns nothing
        local projectiledata dat = GetTimerData(GetExpiredTimer())
        local real angle
        local real nx
        local real ny
        
            if (CRANGE == 600.00) then
                call dat.destroy()
                call RemoveUnit(dat.d)
                call PauseTimer(Projectile_timer)
            else
                set angle = bj_RADTODEG * Atan2(GetLocationY(dat.l) - GetUnitY(dat.d), GetLocationX(dat.l) - GetUnitX(dat.d))
                set nx = GetUnitX(dat.d) + 10.00 * Cos(angle * bj_DEGTORAD)
                set ny = GetUnitY(dat.d) + 10.00 * Sin(angle * bj_DEGTORAD)
                call SetUnitPosition(dat.d, nx, ny )
                set CRANGE = CRANGE + 10.00
            endif
            
    endfunction
    
    private function Actions takes nothing returns nothing
        local unit b = GetTriggerUnit()
        local unit d = CreateUnit(GetOwningPlayer(b), Projectile_Dummy(), GetUnitX(b), GetUnitY(b), 90.00)
        local location l = GetSpellTargetLoc()
        local projectiledata dat = projectiledata.create()
            set dat.x = 0.00
            set dat.y = 0.00
            set dat.d = d
            set dat.l = l
            call TimerStart(Projectile_timer, 0.01, true, function Timer)
            call SetTimerData (Projectile_timer, dat)
    endfunction



some details: i make the function private to don't be redeclared function in other triggers, also it requires TimerUtils (SetTimerData and GetTimerData)

you just forget to restore the value of the struct in Timer function :p


PS: next time use jass section
 

l1lshadow

New Member
Reaction score
4
I changed my code but it gives me an error when I try to save it saying it is an undeclared function. This also isn't in the tutorial.
 

roaaaarrrr

New Member
Reaction score
33
JASS:
if (CRANGE == 600.00) then
                call dat.destroy()
                call RemoveUnit(dat.d)
                call PauseTimer(Projectile_timer)
            else
                set angle = bj_RADTODEG * Atan2(GetLocationY(dat.l) - GetUnitY(dat.d), GetLocationX(dat.l) - GetUnitX(dat.d))
                set nx = GetUnitX(dat.d) + 10.00 * Cos(angle * bj_DEGTORAD)
                set ny = GetUnitY(dat.d) + 10.00 * Sin(angle * bj_DEGTORAD)
                call SetUnitPosition(dat.d, nx, ny )
                set CRANGE = CRANGE + 10.00
            endif


You aren't looping anything, so its only running through the function once...

do something like -

JASS:

loop
                set angle = bj_RADTODEG * Atan2(GetLocationY(dat.l) - GetUnitY(dat.d), GetLocationX(dat.l) - GetUnitX(dat.d))
                set nx = GetUnitX(dat.d) + 10.00 * Cos(angle * bj_DEGTORAD)
                set ny = GetUnitY(dat.d) + 10.00 * Sin(angle * bj_DEGTORAD)
                call SetUnitPosition(dat.d, nx, ny )
                set CRANGE = CRANGE + 10.00
                exitwhen CRANGE > 600
endloop
                call dat.destroy()
                call RemoveUnit(dat.d)
                call PauseTimer(Projectile_timer)
 

Laiev

Hey Listen!!
Reaction score
188
I changed my code but it gives me an error when I try to save it saying it is an undeclared function. This also isn't in the tutorial.

Have you try to get TimerUtils System?

Because I say, this need TimerUtils for store the struct data in the timer and then restore it in the function

If you don't know what is TimerUtils, Click Here!
 
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