• 🏆 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!

[Solved] syntax error

Status
Not open for further replies.
Level 12
Joined
Nov 3, 2013
Messages
989
Warcraft 3 patch: 1.31.1

I get an error on this line call TimerStart(t, tDuration, false, function paranoia_expire(u)) Syntax Error, unexpected "("


I'm assuming that the issue is paranoia_expire(u) but I don't know why.

In 1.27 (JNGP) I don't get any error, though since BlzGetUnitAbilityCooldown doesn't exist I replaced it with a number, so it could also have a problem I suppose.


Since JNGP seemingly had no problem with it, I tried playing the map on 1.31.1 anyway, but that didn't work until I disabled the trigger.


JASS:
function paranoia_expire takes unit u returns nothing
    call UnitRemoveAbility(u, 'A04E')
endfunction


function paranoia_timer takes unit u returns nothing
    local timer t=CreateTimer()
    local real tDuration = BlzGetUnitAbilityCooldown(u, 'A04E', GetUnitAbilityLevel(u, 'A04E'))
    call TimerStart(t, tDuration, false, function paranoia_expire(u))
    set t=null
endfunction



function Trig_Paranoia_2_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A04F' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Paranoia_2_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    call UnitAddAbilityBJ( 'A04E', u )
    call SetUnitAbilityLevelSwapped( u, 'A04E', GetUnitAbilityLevel(u, 'A04F') )
    call paranoia_timer(u)
endfunction

//===========================================================================
function InitTrig_Paranoia_2 takes nothing returns nothing
    set gg_trg_Paranoia_2 = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Paranoia_2, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Paranoia_2, Condition( function Trig_Paranoia_2_Conditions ) )
    call TriggerAddAction( gg_trg_Paranoia_2, function Trig_Paranoia_2_Actions )
endfunction


the trigger is a combination of me converting a GUI trigger into custom text + I copied the timer functions from some tutorial, but I changed it so the function paranoia_expire takes a unit variable, since I wanted that to carry over so I don't have to use a hashtable or anything
 
Level 9
Joined
Mar 26, 2017
Messages
376
Unfortunately you cannot give arguments to a function in a timer.
So you need to put: function paranoia_expire

And you can find the right unit by saving the unit handle id in a hashtable to the timer handle id as a key.
Then retrieve the key via GetExpiredTimer.
 
Level 12
Joined
Nov 3, 2013
Messages
989
Unfortunately you cannot give arguments to a function in a timer.
So you need to put: function paranoia_expire

And you can find the right unit by saving the unit handle id in a hashtable to the timer handle id as a key.
Then retrieve the key via GetExpiredTimer.
Well that's unfortunate, I was hoping I could avoid using a hashtable this way.

One of the bad habits I've gotten from using JNGP is that since I mostly use GUI I avoid hashtables since hashtables don't work with GUI in JNGP...
 
Level 9
Joined
Mar 26, 2017
Messages
376
The reason you need hashtables, is because you can store a very large number. Handle id's are normally like 1 billion+.

You might use a method called handle offset. That means you subtract a large number from the handle id's in order to get them within the 32k range, and then you are able to save it in an array.
 
Status
Not open for further replies.
Top