Jump to content

Error end spected near <eof>


Elmatus

Recommended Posts

I had this script and the console outputs:

SCRIPT ERROR: puertas\script.lua:32: 'end' expected near 'else'

But I can't find the sintax error.

Please help me:

thisi s the code:

  
  
local initPos = 1236.6999511719, 2108.8999023438, 8.6000003814697 
local finaPos = 1236.6999511719, 2108.8999023438, 3.0999999046326 
  
  
function createTheGate() 
  
gate = createObject ( 980, 1236.6999511719, 2108.8999023438, 8.6000003814697, 0, 0, 270 )               
 end 
  
addEventHandler ("onResourceStart", getRootElement, createTheGate) 
  
  
  
function moveTheGate () 
               
if ( getElementPosition (gate) == initPos ) then           
  
  moveObject ( gate, 5000, finaPos ) 
end 
  
  
 if ( getElementPosition (gate) ==  finaPos ) then 
  
moveObject ( gate, 5000, initPos)  
   
end 
  
  
  
 else 
  
  
outputChatBox ( "#ff0000 The gate is moving!", client ) 
  
end 
  
end 
  
addCommandHandler ("gate", moveTheGate) 

Link to comment
local initPos = 1236.6999511719, 2108.8999023438, 8.6000003814697 
local finaPos = 1236.6999511719, 2108.8999023438, 3.0999999046326 
  
  
function createTheGate() 
  
gate = createObject ( 980, 1236.6999511719, 2108.8999023438, 8.6000003814697, 0, 0, 270 )               
 end 
  
addEventHandler ("onResourceStart", getRootElement, createTheGate) 
  
  
  
function moveTheGate () 
              
if ( getElementPosition (gate) == initPos ) then           
  moveObject ( gate, 5000, finaPos ) 
outputChatBox ( "#ff0000 The gate is moving!", client ) 
else if ( getElementPosition (gate) ==  finaPos ) then 
 moveObject ( gate, 5000, initPos) 
outputChatBox ( "#ff0000 The gate is moving!", client ) 
  
end  
end 
  
addCommandHandler ("gate", moveTheGate) 

Link to comment

Oh I think i get it

I was writting:

if  xxxx then 
xxxxx 
end 
else 
xxxxx 

But it was:

if xxxxx then 
xxxx 
else 
xxxx 
end 

The "The gate is moving" Is when the door is not in initPos or in finaPos, so the door is opening, you have to wait to stop moving.

So its

  
  
local initPos = 1236.6999511719, 2108.8999023438, 8.6000003814697 
local finaPos = 1236.6999511719, 2108.8999023438, 3.0999999046326 
  
  
function createTheGate() 
  
gate = createObject ( 980, 1236.6999511719, 2108.8999023438, 8.6000003814697, 0, 0, 270 )               
 end 
  
addEventHandler ("onResourceStart", getRootElement, createTheGate) 
  
  
  
function moveTheGate () 
              
if ( getElementPosition (gate) == initPos ) then           
  
  moveObject ( gate, 5000, finaPos ) 
  
  
 elseif ( getElementPosition (gate) ==  finaPos ) then 
  
moveObject ( gate, 5000, initPos) 
  
  
 else 
  
  
outputChatBox ( "#ff0000 The gate is moving!", client ) 
  
end 
  
end 
  
addCommandHandler ("gate", moveTheGate) 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...