Weird if problem

Posted by Gore on Tue 29 May 2007 10:28 PM — 4 posts, 19,650 views.

#0
function il_curare ()
  if prev_curare == 1 then -- Line 424
    return 'You are afflicted 1.'
    prev_curare = 2 -- Line 426
  end
  if prev_curare == 2 then
    return 'You are afflicted 2.'
    prev_curare = 1
  end
end

function venom_scytherus (n,o,wc)
  Send ('secrete scytherus')
  Send ('conjure '..target['cur']..' illusion '..il['bite']..il['nl']..il_curare())
  Send ('bite '..target['cur'])
  Send ('purge')
end

Compile error
World: Achaea
Immediate execution
[string "Script file"]:426: 'end' expected (to close 'if' at line 424) near 'prev_curare'


Why is it telling me that? heh
Australia Forum Administrator #1
After a "return" it is not logical to put more statements, as they will never be executed.

Thus the line:


prev_curare = 2


... cannot be reached, and it is advising that only "end" is possible here.
USA #2
You might also want to change that around with an if/else just to save a bit of error checking.

function il_curare ()
  if prev_curare == 1 then -- Line 424
    prev_curare = 2 -- Line 426
    return 'You are afflicted 1.'
  elseif prev_curare == 2 then
    prev_curare = 1
    return 'You are afflicted 2.'
  end
end

If you don't use an else, you will validate both of the statements, since you will set prev_curare to 2 before checking if it's set to 2. That might be what you're trying to do though, I admit I don't know much about Achea and it's status affects. This is, of course, only a risk if you change your code to get rid of the returns, but it's a good idea in case you decide make changes at a later date.
Amended on Wed 30 May 2007 02:26 AM by Shaun Biggs
#3
Ah yeah that makes sense, sorry about that, and thanks -g- I had an else statement but I changed it to two seperate if's to see if it would fix the problem. Such simple errors! thanks again.