Elmatus Posted March 3, 2014 Share Posted March 3, 2014 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
WhoAmI Posted March 3, 2014 Share Posted March 3, 2014 Delete one end in line 39, but i think you forgot one if. Link to comment
Castillo Posted March 3, 2014 Share Posted March 3, 2014 That 'else' you have there is the problem, to use an 'else' you need to first use an 'if' statement. Link to comment
Jacobob14 Posted March 3, 2014 Share Posted March 3, 2014 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
Castillo Posted March 3, 2014 Share Posted March 3, 2014 Change "else if" to "elseif". Link to comment
Elmatus Posted March 3, 2014 Author Share Posted March 3, 2014 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
DNL291 Posted March 3, 2014 Share Posted March 3, 2014 Change getRootElement to resourceRoot. Link to comment
Elmatus Posted March 3, 2014 Author Share Posted March 3, 2014 Now its working Thanks a lot SolidSnake for the correction of the syntax Thanks all of the other people that commented. Blesses and have a good afternoon. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now