generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Is it "else if" or "elseif"?

Previous Thread :: Next Thread 
lawl60ftw is not online. lawl60ftw
Joined: 30 May 2009
Total Posts: 3973
25 Oct 2012 12:00 PM
I've always wondered this and never really payed attention when writing scripts like these, it always gets me and I usually don't notice the problem until I've written an entirely new script.

It's like my problem with not noticing " == true" and " = true"
Report Abuse
SolarCrane is not online. SolarCrane
Forum Moderator
Joined: 03 Jul 2012
Total Posts: 116
25 Oct 2012 12:01 PM
Depends on the language, in Lua we like to use elseif
Report Abuse
BJCarpenter is not online. BJCarpenter
Joined: 04 Nov 2008
Total Posts: 4416
25 Oct 2012 12:05 PM
They are two different things:

an elseif tuns an if statement inot a Case statement.

In case of this do that,
case of this do the other
case of last do finale.
Report Abuse
BJCarpenter is not online. BJCarpenter
Joined: 04 Nov 2008
Total Posts: 4416
25 Oct 2012 12:08 PM
It's a Case statement in Pascal.

In Basic, it's an On statement:

ON a=1, 5, -1, 0 GOTO 100, 200, 300, 400

bLAST FORM THE PAST,
Brian

Report Abuse
BJCarpenter is not online. BJCarpenter
Joined: 04 Nov 2008
Total Posts: 4416
25 Oct 2012 12:10 PM
I forgot my line-number.

10 ON a=1, 5, -1, 0 GOTO 100, 200, 300, 400
Report Abuse
SockPuppetCow is not online. SockPuppetCow
Joined: 14 Sep 2012
Total Posts: 121
25 Oct 2012 02:30 PM
Right then, here's the difference:

"elseif" is like turning it into a switch statement (or is it case? Switch-Case?) so it's like this:
If value = 1 then
blah blah blah
elseif 2 then
blah blah
elseif 3 then
blah blah blah
and so on.

"else if" is like putting an if statement inside an if statement, sort of. You would say something like:
if script.Parent.IntValue = 1 then
print("Value = 1")
else if script.Parent.StringValue = ("blah") then
print("IntValue does not equal 1 and StringValue equals blah")

So let's recap:

"else if" is like telling the script, if the value does not fit my specifications, then perform this other if statement.

"elseif" is like testing for multiple different values for different outcomes.

Direct answer to your question:
It depends on what you're trying to do.
Report Abuse
chaoticregandpledge is not online. chaoticregandpledge
Joined: 04 Dec 2009
Total Posts: 2894
25 Oct 2012 02:35 PM
Just use elseif, as using else if would be redundant, and SockPuppetCow's script isn't even fully correct.

Lua Learners - Elite
Report Abuse
SockPuppetCow is not online. SockPuppetCow
Joined: 14 Sep 2012
Total Posts: 121
25 Oct 2012 03:19 PM
Meh. My script wasn't supposed to have any function, it was just an example. But I did get the point across did I not?
Report Abuse
L2000 is not online. L2000
Joined: 03 Apr 2008
Total Posts: 77448
25 Oct 2012 03:31 PM
@Chaotic
It wouldn't need to be fully correct; it still shows an example for the difference between the two, and gives a good explanation on it.

@OP
It's one-word, so "elseif". However, if you wanted something to run for some but not for other cases, then you could use an else, inside that check the ifs, and then run the shared code. So, for example:

if condition then
-- code
elseif cond2 then
-- code 2
-- shared code
elseif cond3 then
-- code 3
-- shared code
end

That could be simpler with this:

if condition then
-- code
else
if cond2 then
-- code two
elseif cond3 then
-- code three
end
-- shared code
end
end

So, basically, for most if statements, you'd use elseif.
Report Abuse
chaoticregandpledge is not online. chaoticregandpledge
Joined: 04 Dec 2009
Total Posts: 2894
25 Oct 2012 06:02 PM
But my point is that you would never use else and then an if statement right after it. It's redundant, just use elseif.

Lua Learners - Elite
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image