HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

function not working (snytax error) & Question

03-01-2007, 10:00 PM#1
Mythic Fr0st
Collapse JASS:
function CastSpell takes unit u2, unit target2 returns nothing
 local timer t = GetExpiredTimer()
 local integer i = GetPlayerId(GetOwningPlayer(u2))+1
 local real x = GetUnitX(u2)
 local real y = GetUnitY(u2)
 local unit d = CreateUnit(i, udg_Dummy_Unit, x, y, 270.00)
    call IssueTargetOrderBJ(u2, "deathcoil", target2)
    call RemoveUnit(d)
    set d = null
    set t = null
endfunction

function StartTimer takes nothing returns nothing
 local timer t = CreateTimer()
 local unit u = GetTriggerUnit()
 local unit target = GetSpellTargetUnit()
 local integer lvl = GetUnitAbilityLevel(u, udg_Ability_To_Cast)
    call TimerStart(t, 0.25, false, function CastSpell(u, target))
endfunction
The error is when trying to add parameters to the function CastSpell()

without the (u, target) it works, but I need them
If I can't do that i'll use game cache

Question 1: if I do call StoreInteger(udg_c, "cast_spell", "unit" H2I(u))

and it runs once, then again by someone else
Will the data in the category "cast_spell" as "unit" be erased?

and be replaced by the new one? (I assume so)
03-01-2007, 10:25 PM#2
Joker
you can only add variables to a trigger when you do
Collapse JASS:
call *function name(variables)*
(i think)
03-01-2007, 10:30 PM#3
Omnikron13
Well, when I tried it out in the WE, I got a syntax error where you passed CreateUnit an integer to refer to the player, and when I swap the 'i' to Player(i) it seems to fix that error. Handles and integers are not freely exchangable, yes?

Though, I don't think that is exactly going to help you with this, even if I am correct...

I believe Joker is right, hovever, as I've only seen things expecting code go function FunctionName without any brackets.

My suggestion is assume this is correct and see if you can get your desired effects without passing parameters. However, the hopefully a more experienced JASS programmer can shed more light on the situation soon.
03-02-2007, 12:41 AM#4
wantok
Joker is right. You can't pass variables to timer callback functions like that. To pass those units to the function you'll have to use some other method like structs, gamecache, or globals.

Edit: ah I didnt read your whole question

You are correct that the value would be overwritten if you did it that way. If you attach the units to the timer using something like local handle variables (SetHandleHandle) you won't have to worry about that.
03-02-2007, 10:42 AM#5
Toink
Collapse JASS:
function CastSpell takes unit u2, unit target2 returns nothing
 local timer t = NewTimer()
 local unit u = GetAttachedUnit(t, "U")
 local unit target = GetAttachedUnit(t, "target")
 local integer lvl = GetAttachedInt(t, "LVL")
     call CasterCastAbilityLevel(GetOwningPlayer(u), udg_Ability_To_Cast, lvl, "deathcoil", target, true)
    set u = null
    set target = null
    call CleanAttachedVars(t)
    call ReleaseTimer(t)
endfunction

function StartTimer takes nothing returns nothing
 local timer t = CreateTimer()
 local unit u = GetTriggerUnit()
 local unit target = GetSpellTargetUnit()
 local integer lvl = GetUnitAbilityLevel(u, udg_Ability_To_Cast)
    call AttachObject(t, "U", u)
    call AttachInt(t, "LVL", lvl)
    call AttachObject(t, "target", target)
    call TimerStart(t, 0.25, false, function CastSpell)
    set u = null
    set target = null
endfunction

Fixed that for you. This script only works with Vexorian's Caster System