Chaos Project

RPG Maker => General Discussion => Troubleshooting / Help => Topic started by: Zexion on April 04, 2013, 12:17:19 am

Title: elsif and else if ?
Post by: Zexion on April 04, 2013, 12:17:19 am
What exactly is the difference? I used elsif right now, and it worked fine, and then added some stuff and changed it to else if just for the sake of making it look nicer, imo. The first returned no errors, the second caused the script to hang, and a syntax error requiring an extra end.

So, like I said. What exactly is the difference of elsif and else if?
Title: Re: elsif and else if ?
Post by: Blizzard on April 04, 2013, 02:47:05 am
This statement doesn't work in Ruby:

if X
else if Y
else
end


That's because the second "else" is a new block and requires another end to close it. With proper indentation, it would look like this:

if X
else if Y
 else
 end
end


Or:

if X
else
 if Y
 else
 end
end


The difference is that you can easily chain multiple elsifs.

if X
elsif Y
elsif Z
elsif W
elsif U
end


It's easier to overview even though it is the same as this one:

if X
else
 if Y
 else
   if Z
   else
     if W
     else
       if U
       else
       end
     end
   end
 end
end
Title: Re: elsif and else if ?
Post by: Zexion on April 04, 2013, 10:12:50 am
Oh okay, so it's just something to make scripting easier?
Title: Re: elsif and else if ?
Post by: Blizzard on April 04, 2013, 11:26:07 am
Yeah, pretty much.