• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Jass scripting not working...

Status
Not open for further replies.
Level 5
Joined
Jul 17, 2006
Messages
145
alright, im using this jass script here and its not working...at all. I the ability and it dosent do anything......

Code:
function Rocket_Engines_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A04D'
endfunction

function Rocket_Engines_Knockback takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit cast = GetAttachedUnit(t, "cast")
    local integer steps = GetAttachedInt(t, "steps")
    call SetUnitPositionLoc(cast, PolarProjectionBJ(GetUnitLoc(cast), 2.5, GetUnitFacing(cast)))        
    set cast = null
    set t = null
    if (steps <= 1) then
        call FlushHandle(t)
        call DestroyTimer(t)
        return    
    endif
    call AttachInt(t, "steps", steps-1)
endfunction

function Rocket_Engines_Actions takes nothing returns nothing
    local timer t
    local real channeltime
    local unit cast = GetTriggerUnit()
    local real steps
    set channeltime = 5.00
    set steps = channeltime/.025
    call AttachInt(t, "steps", R2I(steps))
    call AttachObject(t, "cast", cast)
    call TimerStart(t, .025, true, function Rocket_Engines_Knockback)
    set cast = null
    set t = null
    set channeltime = 0
endfunction

//===========================================================================
function InitTrig_Captian_Germross_Rocket_Engines takes nothing returns nothing
    set gg_trg_Captian_Germross_Rocket_Engines = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Captian_Germross_Rocket_Engines, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Captian_Germross_Rocket_Engines, Condition( function Rocket_Engines_Conditions ) )
    call TriggerAddAction( gg_trg_Captian_Germross_Rocket_Engines, function Rocket_Engines_Actions )
endfunction
[\code]

I am using a cache system that can be found here:
http://forums.dota-allstars.com/index.php?showtopic=92616
(the first shown script)

all help is appreciated.
 
Level 11
Joined
Jul 12, 2005
Messages
764
you do not create the timer that should expire...
local timer t = CreateTimer()

There were other problems:
1. You used unnecessary locals in the Actions (channeltime, steps)
2. You don't need to nullify reals, and integers, only handles (like units, locations, etc...)
3. Learn how to use coordinates instead of locations
4. You nullified the timer (t), but it would be still in use for getting "steps"
5. You don't need that 'return' as it will break the function without executing it completely
6. It created 400 location leaks each cast...

I optimized the code for you:
Code:
function Rocket_Engines_Knockback takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit cast = GetAttachedUnit(t, "cast")
    local location curr = GetUnitLoc(cast)
    local location dest = PolarProjectionBJ(curr, 2.5, GetUnitFacing(cast))
    call SetUnitPositionLoc(cast, dest)
    call RemoveLocation(curr)
    call RemoveLocation(dest)
    if GetAttachedInt(t, "steps") <= 1 then
        call FlushHandle(t)
        call DestroyTimer(t)
    else
        call AttachInt(t, "steps", GetAttachedInt(t, "steps")-1)
    endif
    set t = null
    set cast = null
    set curr = null
    set dest = null
endfunction

function Rocket_Engines_Actions takes nothing returns nothing
    local timer t = CreateTimer()
    local unit cast = GetTriggerUnit()
    call AttachInt(t, "steps", 200)
    call AttachObject(t, "cast", cast)
    call TimerStart(t, .025, true, function Rocket_Engines_Knockback)
    set cast = null
    set t = null
endfunction
 
Last edited:
Level 5
Joined
Jul 17, 2006
Messages
145
you do not create the timer that should expire...
local timer t = CreateTimer()

OH S**T lol i should have caught that

There were other problems:
1. You used unnecessary locals in the Actions (channeltime, steps)
2. You don't need to nullify reals, and integers, only handles (like units, locations, etc...)
3. Learn how to use coordinates instead of locations
4. You nullified the timer (t), but it would be still in use for getting "steps"
5. You don't need that 'return' as it will break the function without executing it completely
6. It created 400 location leaks each cast...

1. accually the channeltime var is important, it will change i just wanted to make sure the base code worked before i started elaborating

2. i know but i like to anyways >_>

3. :/ im still pretty new but ok

4. ...hmm how could you explain please? :D im new help is appreciated

5. alright that part of the code i got from a template and i figured something bad would happen if i dident put it there.

6. O_O how? ill use cordanates but id still like to know XD

btw your example dosent really use coordanates XD
 
Level 11
Joined
Jul 12, 2005
Messages
764
1. OK, sry then for deleting...
2. Script loses some efficiency, but not that big problem...
3. It is only a suggestion
4.
set t = null
if (steps <= 1) then
call FlushHandle(t)
call DestroyTimer(t)
return
endif
call AttachInt(t, "steps", steps-1)

You nullified t, but it is still in use. In case, the timer would not be destroyed, and we don't want that, do we? :D

5. Allright, you don't need to put that in a timer...

6. OK, the timer expires 200 times. Look a this line:
call SetUnitPositionLoc(cast, PolarProjectionBJ(GetUnitLoc(cast), 2.5, GetUnitFacing(cast)))
-> creates 1 location with GetUnitLoc(cast)
-> and 1 with PolarProjectionBJ(..)
So the timer creates 2 (undestroyed) locations, and it expires 200 times.
==> 400 location leaks (Cool, isn't it XD)
This is why we have to store the locations into variables, and destroy them with call RemoveLocation(<loc>)

Now you probably see why it's recommended to use coordinates, you don't need variables for the locations. It's not that hard, trust me! ;)
 
Level 5
Joined
Jul 17, 2006
Messages
145
ok well look at it now, its fixed up some.

I dident use coordanates, i was to lazy seeing as all i had to do was add a few vars and copy/paste what i already had onto them :p

Anyways, this works well but if you see any leaks ect tell me :D

Code:
function Rocket_Engines_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A04D'
endfunction

function Rocket_Engines_Knockback takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit cast = GetAttachedUnit(t, "cast")
    local integer steps = GetAttachedInt(t, "steps")
    local location curr = GetUnitLoc(cast)
    local location dest = PolarProjectionBJ(curr, 25, GetUnitFacing(cast))
    call SetUnitPositionLoc(cast, dest)
    call RemoveLocation(curr)
    call RemoveLocation(dest)        
    set cast = null
    set curr = null
    set dest = null
    if (steps <= 1) then
        call FlushHandle(t)
        call DestroyTimer(t)
        set t = null
        return    
    endif
    set t = null
    call AttachInt(t, "steps", steps-1)
endfunction

function Rocket_Engines_Actions takes nothing returns nothing
    local timer t = CreateTimer()
    local real channeltime
    local unit cast = GetTriggerUnit()
    local real steps
    set channeltime = 2.00
    set steps = channeltime/.025
    call AttachInt(t, "steps", R2I(steps))
    call AttachObject(t, "cast", cast)
    call TimerStart(t, .025, true, function Rocket_Engines_Knockback)
    set cast = null
    set t = null
    set channeltime = 0
endfunction

//===========================================================================
function InitTrig_Captian_Germross_Rocket_Engines takes nothing returns nothing
    set gg_trg_Captian_Germross_Rocket_Engines = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Captian_Germross_Rocket_Engines, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Captian_Germross_Rocket_Engines, Condition( function Rocket_Engines_Conditions ) )
    call TriggerAddAction( gg_trg_Captian_Germross_Rocket_Engines, function Rocket_Engines_Actions )
endfunction
 
Level 11
Joined
Jul 12, 2005
Messages
764
Pff... Many problems with this part:

if (steps <= 1) then
call FlushHandle(t)
call DestroyTimer(t)
set t = null
return
endif
set t = null
call AttachInt(t, "steps", steps-1)

1. As i said, forget that 'return'!!
2. You nullify t twice
3. The last line still uses 't' as a parameter, but it is already nulled...

Correct:

if steps <= 1 then
call FlushHandle(t)
call DestroyTimer(t)
else
call AttachInt(t, "steps", steps-1)
endif
set t = null
 
Status
Not open for further replies.
Top