• 🏆 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] Evil Compiler - Cant fix my problem!

Status
Not open for further replies.
Level 9
Joined
Aug 27, 2004
Messages
471
Ok, i am geeting FED UP with wc3's jass compiler.
I have some nice, well written, easy to understand jass blowback trigger, that fires whenever a footmen attacks:
JASS:
function c_001 takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetAttacker()) == 'hfoo' ) ) then
        return false
    endif
    return true
endfunction

function k_001 takes unit target, real bbspeed, unit cast returns nothing
local location castpo = GetUnitLoc(cast)
local location targetpo = GetUnitLoc(target)
call SetUnitPositionLoc(target, PolarProjectionBJ(castpo, DistanceBetweenPoints(castpo, targetpo+10), AngleBetweenPoints(castpo, targetpo)))
call RemoveLocation(castpo)
call RemoveLocation(targetpo)
endfunction

function s_001 takes nothing returns nothing
local timer t1
local unit cast
local unit target
set cast = GetAbilityUnit()
set target = GetSpellTargetUnit()
set t1 = CreateTimer(t, 0.03, true, function k_001(target, 6.00, cast)
call TriggerSleepAction(0.30)
call DestroyTimer(t1)
set cast = null
set target = null
set t1 = null
endfunction

function InitTrig_trigger takes nothing returns nothing
    local trigger t
    set t= CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_ATTACKED)
    call TriggerAddCondition(t, Condition(function c_001))
    call TriggerAddAction(t, function s_001)
endfunction

I get 3 errors:
line 26 - Invalid type for specified operator.
line 35 - Expected a name
line 37 - Expected a name

I am so tired, did i miss something obvious? So confused... What is wrong gaahhhh! HELP ME AHHH :p.

Tanks for your help in advanced, modeler :p.
 
Level 3
Joined
Mar 27, 2004
Messages
70
This line is wrong:
JASS:
set t1 = CreateTimer(t, 0.03, true, function k_001(target, 6.00, cast)

You cannot pass parameters to a code parameter, AND you are mixing CreateTimer and TimerStart together.
 
Level 3
Joined
Jul 12, 2005
Messages
48
Also your condition can be simplified to:
JASS:
function c_001 takes nothing returns boolean
return GetUnitTypeId(GetAttacker()) == 'hfoo'
endfunction
 
Level 9
Joined
Aug 27, 2004
Messages
471
KaTTaNa said:
This line is wrong:
JASS:
set t1 = CreateTimer(t, 0.03, true, function k_001(target, 6.00, cast)

You cannot pass parameters to a code parameter, AND you are mixing CreateTimer and TimerStart together.

>.>
I got the jist of what you said (i hope)... So I cannot pass parameters to a code parameter... so you mean function k_001(target, 6.00, cast) is invalid yes? And even if my timer worked, it wouldent start yes?

So how do i fix it...
Locals wont pass, so i need to change them to universal.

So... after some modifications i still get the errors:
Line 29: Invalid Type for specified operaor
&
Line 39: Expected '
...
Expected '... What in hell does that mean... I need to write down theyse errors & their fixs >.>.

Well the revised code (damn i had alot of minute errors):

-Edit got rid of the expected ' by removing the k_001() and revising it to k_001. Only error now is:
Line 29: invalid type for specified operator.
Line 29 jass:
JASS:
call SetUnitPositionLoc(udg_target, PolarProjectionBJ(castpo, DistanceBetweenPoints(castpo, targetpo+10), AngleBetweenPoints(castpo, targetpo)))
function c_001 takes nothing returns boolean
if ( not ( GetUnitTypeId(GetAttacker()) == 'hfoo' ) ) then
return false
endif
return true
endfunction

function k_001 takes nothing returns nothing
local location castpo = GetUnitLoc(udg_cast)
local location targetpo = GetUnitLoc(udg_target)
call SetUnitPositionLoc(udg_target, PolarProjectionBJ(castpo, DistanceBetweenPoints(castpo, targetpo+10), AngleBetweenPoints(castpo, targetpo)))
call RemoveLocation(castpo)
call RemoveLocation(targetpo)
endfunction

function s_001 takes nothing returns nothing
local timer t1
set udg_cast = GetSpellAbilityUnit()
set udg_target = GetSpellTargetUnit()
set t1 = CreateTimer()
call TimerStart(t1, 0.01, true, function k_001)
call TriggerSleepAction(0.30)
call DestroyTimer(t1)
set udg_cast = null
set udg_target = null
set t1 = null
endfunction

function InitTrig_trigger takes nothing returns nothing
local trigger t
set t= CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_ATTACKED)
call TriggerAddCondition(t, Condition(function c_001))
call TriggerAddAction(t, function s_001)
endfunction
[/code]
Full script:

I learned something today... NEVER expect to write good jass when you are drooling from sleep deprivation! :p

Once again thx for the help. (And thanks for the pointers kat!)
 
Level 3
Joined
Mar 27, 2004
Messages
70
So how do i fix it...
Locals wont pass, so i need to change them to universal.
I wrote a tutorial on how to beat that issue. Using globals tend to get messy because if your trigger runs more than once at the same time, everything will be messed up.
You can read the tutorial, but it is very generic so you may have a hard time understanding how it works.
The Handle Variables are the solution to your problem, take your time to learn how to use them.

In your code, this line is wrong:
JASS:
call SetUnitPositionLoc(udg_target, PolarProjectionBJ(castpo, DistanceBetweenPoints(castpo, targetpo+10), AngleBetweenPoints(castpo, targetpo))) 
// targetpo + 10 is not a valid operation, since targetpo is a location (2 coordinates) and 10 is a number (real or integer)
// Try this:
call SetUnitPositionLoc(udg_target, PolarProjectionBJ(castpo, DistanceBetweenPoints(castpo, targetpo)+10, AngleBetweenPoints(castpo, targetpo)))
// What you want is to do distance+10, not targetpo+10


Using the method I proposed, and some trigonometry instead of locations, it would look like this:
JASS:
function c_001 takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetAttacker()) == 'hfoo' ) ) then
        return false
    endif
        return true
endfunction

function k_001 takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit caster = GetHandleUnit( t, "caster" ) // This is the caster we stored in s_001
    local unit target = GetHandleUnit( t, "target" ) // This is the target we stored in s_001
    local real angle = Atan2( GetUnitY(target)-GetUnitY(caster), GetUnitX(target)-GetUnitX(caster) )
    local real time = GetHandleReal( t, "time" ) + 0.01
    call SetUnitPosition(target, GetUnitX(target)+Cos(angle)*10, GetUnitY(target)+Sin(angle)*10 )
    if time > 0.30 then
        call FlushHandleLocals( t )
        call DestroyTimer( t )
    else
        call SetHandleReal( t, "time", time )
    endif
    set t = null
    set caster = null
    set target = null
endfunction

function s_001 takes nothing returns nothing
    local timer t1 = CreateTimer()
    call SetHandleHandle( t1, "caster", GetSpellAbilityUnit() )
    call SetHandleHandle( t1, "target", GetSpellTargetUnit() )
    call TimerStart(t1, 0.01, true, function k_001)
    set t1 = null
    // The timer will destroy itself
endfunction

function InitTrig_trigger takes nothing returns nothing
    local trigger t
    set t= CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_ATTACKED)
    call TriggerAddCondition(t, Condition(function c_001))
    call TriggerAddAction(t, function s_001)
endfunction
 
Status
Not open for further replies.
Top