HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Errors in Code, whats wrong with my syntax?

11-10-2007, 04:09 AM#1
Salbrismind
I started doing some of my first out of tutorial Jass coding but I've ran into some problems when I tried saving the map...

It tells me on this line:
local unit Otheru =udg_ship[tempI+(3-(count-tempI))]

That it expects set? (I'll post the whole code at the bottom so you can see that it is in an if and maybe that has a connection?)


Various times it says that It expects "then" for if's like these:
if udg_curangle[count] > 90, udg_curangle[count] < 270 then
if GetUnitFacing(u) > 90, GetUnitFacing(u) < 270 then

Yet, for some reason it doesn't bother with this:
elseif udg_curangle[count] > 270, udg_curangle[count] < 90 then


Everything line inside the if's is a local variable declaration and it says for each line that it expects "endif". (this includes everything inside the if's even the elseif)


Then at the end I use two SetUnitPositon functions and for both it "expects a name":
call SetUnitPosition (Otheru, tempxo, tempyo)
call SetUnitPosition (u, tempx, tempy)


And for my anti-leak part I null out all my handles and it says "expected a variable name":
set Otherpos = null
set Otheru = null




Collapse JASS:
function Endless_Arena_x_Actions takes unit u, location pos returns nothing
local integer count = 0
local integer tempI
loop
    set count = count + 1
    if udg_ship[count] == u then
    tempI = (R2I(count/2-0.6))     
    local unit Otheru = udg_ship[tempI+(3-(count-tempI))]
    exitwhen udg_ship[count] == u 
    endif
endloop
local location Otherpos = GetUnitLoc(Otheru)
if udg_curangle[count] > 90 , udg_curangle[count] < 270 then
    if GetUnitFacing(u) > 90, GetUnitFacing(u) < 270 then
    local real tempx = (-1*GetLocationX(pos)) + GetLocationX(pos) - GetLocationX(Otherpos)           
    local real tempy = GetLocationY (pos)
    local real tempxo = -1 * GetLocationX(pos)
    local real tempyo = GetLocationY (pos)
    elseif GetUnitFacing(u) > 270, GetUnitFacing(u) < 90 then
    local real tempx = (-1*GetLocationX(pos)) + GetLocationX(pos) - GetLocationX(Otherpos) + (ISignBJ(GetLocationX(pos))*1500)          
    local real tempy = GetLocationY (pos)
    local real tempxo = -1 * GetLocationX(pos) + (ISignBJ(GetLocationX(pos))*1500)
    local real tempyo = GetLocationY (pos)
    endif
elseif udg_curangle[count] > 270, udg_curangle[count] < 90 then
    if GetUnitFacing(u) > 270, GetUnitFacing(u) < 90 then
    local real tempx = (-1*GetLocationX(pos)) + GetLocationX(pos) - GetLocationX(Otherpos)           
    local real tempy = GetLocationY (pos)
    local real tempxo = -1 * GetLocationX(pos)
    local real tempyo = GetLocationY (pos)
    elseif GetUnitFacing(u) > 90, GetUnitFacing(u) < 270 then
    local real tempx = (-1*GetLocationX(pos)) + GetLocationX(pos) - GetLocationX(Otherpos) + (ISignBJ(GetLocationX(pos))*1500)          
    local real tempy = GetLocationY (pos)
    local real tempxo = -1 * GetLocationX(pos) + (ISignBJ(GetLocationX(pos))*1500)
    local real tempyo = GetLocationY (pos)     
    endif
endif
call SetUnitPosition (Otheru, tempxo, tempyo)
call SetUnitPosition (u, tempx, tempy)
set Otherpos = null
set Otheru = null  
endfunction

function Trig_Endless_Arena_x_Actions takes nothing returns nothing
    call Endless_Arena_x_Actions ( GetTriggerUnit(), GetUnitLoc(GetTriggerUnit()) )
endfunction

//===========================================================================
function InitTrig_Endless_Arena_x takes nothing returns nothing
    set gg_trg_Endless_Arena_x = CreateTrigger(  )
    call TriggerRegisterLeaveRectSimple( gg_trg_Endless_Arena_x, Rect(-6000.00, -6100.00, 6000.00, 6100.00) )
    call TriggerAddAction( gg_trg_Endless_Arena_x, function Trig_Endless_Arena_x_Actions )
    set gg_trg_Endless_Arena_x = null
endfunction
11-10-2007, 04:37 AM#2
PipeDream
Local variables can only be declared at the top of a function
11-10-2007, 04:18 PM#3
Salbrismind
Quote:
Originally Posted by PipeDream
Local variables can only be declared at the top of a function

Before anyother code or just not inside loops and ifs?:

function......
local...
local....
set....
local....

in this example would the last local work?
11-10-2007, 04:26 PM#4
HINDYhat
No it wouldn't.

ALL locals have to be declared first thing in a function.
11-10-2007, 04:32 PM#5
Salbrismind
Quote:
Originally Posted by HINDYhat
No it wouldn't.

ALL locals have to be declared first thing in a function.

Thanks, I'll modify the code and post again if it works/doesn't.
11-10-2007, 04:41 PM#6
Salbrismind
It still doesn't but the errors related to the locals has gone away. The ifs now are giving me problems.

For some reason on my first two if lines:

if udg_curangle[count] > 90 , udg_curangle[count] < 270 then
if GetUnitFacing(u) > 90, GetUnitFacing(u) < 270 then

it says expects then. So does that mean I can't have two conditions for a if?
How would I do this then?
11-10-2007, 04:47 PM#7
Fireeye
if you want 2 conditions in a if-condition you need to use 'and' instead of ','
11-10-2007, 04:54 PM#8
Salbrismind
Quote:
Originally Posted by Fireeye
if you want 2 conditions in a if-condition you need to use 'and' instead of ','

oh... I just looked in the jasscraft list of natives and it showed and... but its capitalized no wonder it didn't work before.

Thanks.
___________________________________________________________________________________
Edited: I tried adding "And" to my ifs like this:
if And( udg_curangle[count] < 270, udg_curangle[count] > 90 ) then
if And( GetUnitFacing(u) > 90, GetUnitFacing(u) < 270 ) then

How do I do it properly?
11-10-2007, 05:13 PM#9
cohadar
Quote:
Originally Posted by Salbrismind
oh... I just looked in the jasscraft list of natives and it showed and... but its capitalized no wonder it didn't work before.

Thanks.
___________________________________________________________________________________
Edited: I tried adding "And" to my ifs like this:
if And( udg_curangle[count] < 270, udg_curangle[count] > 90 ) then
if And( GetUnitFacing(u) > 90, GetUnitFacing(u) < 270 ) then

How do I do it properly?

Collapse JASS:
if  udg_curangle[count] < 270 and  udg_curangle[count] > 90  then
    if  GetUnitFacing(u) > 90 and GetUnitFacing(u) < 270  then
11-10-2007, 06:59 PM#10
Salbrismind
Quote:
Originally Posted by cohadar
Collapse JASS:
if  udg_curangle[count] < 270 and  udg_curangle[count] > 90  then
    if  GetUnitFacing(u) > 90 and GetUnitFacing(u) < 270  then

Awww, now I see. I just got confused when I typed it in Jasscraft because it didn't colour it and I've learned that anything not coloured is thought of as a variable.