HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Expected "endif" compile error

05-04-2004, 12:34 PM#1
th15
I don't know much about JASS, I was just trying to get it to use local variables but everytime i try to save my map it gives me errors on this lines

Code:
function Trig_Disable_bugs_2_Actions takes nothing returns nothing
    if ( Trig_Disable_bugs_2_Func001C() ) then
        local unit udg_tempunit = GetAttackedUnitBJ()
        local location udg_temploc = GetUnitLoc(udg_tempunit)

It says "Expected 'endif'" on the last two lines of that. I've been looking through my stuff and i just can't figure it out.

These two functions are custom script lines at the start of the "then" portion of an if-then-else. The rest of the stuff is done with GUI triggers using WEU.

Speaking of WEU, is it true that WEU automatically destroys variables for you? UMSWE had that function built into it but WEU doesn't seem to have it.
05-04-2004, 12:50 PM#2
The Gearhead
Code:
function Trig_Disable_bugs_2_Actions takes nothing returns nothing
    if ( Trig_Disable_bugs_2_Func001C() ) then
        local unit udg_tempunit = GetAttackedUnitBJ()
        local location udg_temploc = GetUnitLoc(udg_tempunit)
    [b]endif[/b]
[b]endfunction[/b]
05-04-2004, 01:00 PM#3
th15
Quote:
Originally Posted by The Gearhead
Code:
function Trig_Disable_bugs_2_Actions takes nothing returns nothing
    if ( Trig_Disable_bugs_2_Func001C() ) then
        local unit udg_tempunit = GetAttackedUnitBJ()
        local location udg_temploc = GetUnitLoc(udg_tempunit)
    [b]endif[/b]
[b]endfunction[/b]

I just tried this and now i've got 4 errors. Why don't i post the entire trigger...

EDIT : You might have noticed i missed the "endfunction" bit. I just tried that and got like dozens of errors.

Code:
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    If - Conditions
        ((Attacked unit) is alive) Equal to True
        (Custom value of (Attacked unit)) Not equal to 1
        (Percentage life of (Attacked unit)) Less than or equal to 25.00
    Then - Actions
        Custom script: local unit udg_tempunit = GetAttackedUnitBJ()
        Custom script: local location udg_temploc = GetUnitLoc(udg_tempunit)
        Custom script: endif
        Unit - Order tempunit to Stop
        Advanced - Remove the Attack ability from tempunit
        Advanced - Remove the Move ability from tempunit
        Unit - Set the custom value of tempunit to 1
        Animation - Play tempunit's Animationname - Death (Units, Buildings, Doodads) animation
        Special Effect - Create a special effect attached to the chest of tempunit using Objects\Spawnmodels\Naga\NagaBlood\NagaBloodWindserpent.mdl
        Player - Add (Point-value of tempunit) to (Owner of (Attacking unit)) Current gold
        Hero - Add (Point-value of tempunit) experience to (Attacking unit), Show level-up graphics
        Advanced - Simulate receipt of (Point-value of tempunit) gold at point ((X of temploc),(Y of temploc))
        Wait 3.00 seconds
        Animation - Play tempunit's Animationname - Decay (Units, Buildings) animation
        Wait 3.00 seconds
        Unit - Move tempunit instantly to (Point(0.00, 0.00))
        Unit - Explode tempunit
        Custom script: call RemoveLocation(udg_temploc)
        Custom script: call RemoveUnit(udg_tempunit)
    Else - Actions

Thats the GUI. This is the raw JASS.

Code:
//===========================================================================
// Trigger: Disable bugs TEMP
//===========================================================================
function Trig_Disable_bugs_TEMP_Func001C takes nothing returns boolean
    if ( not ( IsUnitAliveBJ(GetAttackedUnitBJ()) == true ) ) then
        return false
    endif
    if ( not ( GetUnitUserData(GetAttackedUnitBJ()) != 1 ) ) then
        return false
    endif
    if ( not ( GetUnitLifePercent(GetAttackedUnitBJ()) <= 25.00 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Disable_bugs_TEMP_Actions takes nothing returns nothing
    if ( Trig_Disable_bugs_TEMP_Func001C() ) then
        local unit udg_tempunit = GetAttackedUnitBJ()
        local location udg_temploc = GetUnitLoc(udg_tempunit)
        endif
        call IssueImmediateOrderBJ( udg_tempunit, "stop" )
        call RemoveBasicAbility( 'Aatk', udg_tempunit )
        call RemoveBasicAbility( 'Amov', udg_tempunit )
        call SetUnitUserData( udg_tempunit, 1 )
        call SetUnitAnimation( udg_tempunit, "death" )
        call AddSpecialEffectTargetUnitBJ( "chest", udg_tempunit, "Objects\\Spawnmodels\\Naga\\NagaBlood\\NagaBloodWindserpent.mdl" )
        call AdjustPlayerStateBJ( GetUnitPointValue(udg_tempunit), GetOwningPlayer(GetAttacker()), PLAYER_STATE_RESOURCE_GOLD )
        call AddHeroXPSwapped( GetUnitPointValue(udg_tempunit), GetAttacker(), true )
        call GoldText( GetUnitPointValue(udg_tempunit), GetLocationX(udg_temploc), GetLocationY(udg_temploc) )
        call TriggerSleepAction( 3.00 )
        call SetUnitAnimation( udg_tempunit, "decay" )
        call TriggerSleepAction( 3.00 )
        call SetUnitPositionLoc( udg_tempunit, Location(0, 0) )
        call ExplodeUnitBJ( udg_tempunit )
        call RemoveLocation(udg_temploc)
        call RemoveUnit(udg_tempunit)
    else
    endif
endfunction

//===========================================================================
function InitTrig_Disable_bugs_TEMP takes nothing returns nothing
    set gg_trg_Disable_bugs_TEMP = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Disable_bugs_TEMP, function Trig_Disable_bugs_TEMP_Actions )
endfunction

Sorry if that was a massive pageful, but at least this way it's open for everyone to see.
05-04-2004, 01:04 PM#4
NES1020
Problem is here.

if ( Trig_Disable_bugs_TEMP_Func001C() ) then <- this one... and
local unit udg_tempunit = GetAttackedUnitBJ()
local location udg_temploc = GetUnitLoc(udg_tempunit)
endif <- this one.

'endif' is already placed end of the trigger. But, you must create locals at the top of the map.

fix like this.

local unit udg_tempunit = GetAttackedUnitBJ()
local location udg_temploc = GetUnitLoc(udg_tempunit)
if ( Trig_Disable_bugs_TEMP_Func001C() ) then
05-04-2004, 01:16 PM#5
th15
Eh, I don't understand something here. Reading vex's local variable tutorial he says that local variables declared outside of an if loop can't be used within the loop. Something about the weird way blizzard coded scoping. Perhaps if I declared the variables at map init? The map is done in GUI so maybe that's why something isn't working.

For now I'm using another method to get the same effect, its just that this way i've got to repeat a lot of my actions.
05-04-2004, 01:21 PM#6
NES1020
function examination takes nothing returns nothing
local integer n = 1
local boolean b = true

if true then
loop
exitwhen n > 10
if n > 2 then
set b = true
set n = n + 1
endif
endloop
endif
endfunction

this works with no problem.
05-04-2004, 02:05 PM#7
Narwanza
I think you misunderstood vexorian. Local variables cannot be used in another function, unless passed, but they can be used anywhere in the function they are defined. You can't define them anywhere else. Oh, and also if you don't have any else conditions, the else isn't needed. This is perfectly fine.

Code:
if (i > 0) then
    return
endif

While this next example works just as well, the first one is easier to read

Code:
if (i > 0) then
    return
else
endif
05-04-2004, 02:54 PM#8
Cubasis
What vexorian was trying to warn....is that you can't use your local variables... inside your "if conditions"...as GUI creates external functions for those, and ofcourse you can't use your local in another function.

That is the only problem. This is the same problem with "Pick all units in group and do action" actions, can't use your locals there, as these actions get put in another function.
05-04-2004, 04:03 PM#9
th15
Ah i understand now. Still quite lost with JASS syntax, but at least i understand its quirks a little more. Thanks for the help guys.