Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Scripting Language

Johnathan Escher
Registered User
Join date: 31 Dec 2002
Posts: 25
01-27-2003 10:24
Could you please add an ELSEIF or CASE statement to the scripting language? Or possibly even both?
Wednesday Grimm
Ex Libris
Join date: 9 Jan 2003
Posts: 934
01-27-2003 10:44
What's wrong with
CODE

if (foo)
{
}
else
{
if (bar)
{
}
else
{
if (baz)
{
}
else
{
}
}
}

?

Or the slightly prettier but more error prone
CODE

if (foo)
{
jump end;
}
if (bar)
{
jump end;
}
if (baz)
{
jump end;
}
else
{
jump end;
}

@end
Johnathan Escher
Registered User
Join date: 31 Dec 2002
Posts: 25
01-27-2003 10:49
The first example is kind of sloppy and gets kind of hard to read. As for the second example, what happens if more than one of foo, bar, or baz is true? That's fine if you want every one that's true to executed, but with case and elseif, you get to have an order of precidence.
Wednesday Grimm
Ex Libris
Join date: 9 Jan 2003
Posts: 934
01-27-2003 11:12
From: someone
Originally posted by Johnathan Escher
As for the second example, what happens if more than one of foo, bar, or baz is true? That's fine if you want every one that's true to executed, but with case and elseif, you get to have an order of precidence.


The "jump end; ... @end" lines mean only one of the cases is executed.

of course if you were particularly perverse you could have
CODE

if (foo) { }
if (bar && !foo) { }
if (baz && !foo && !bar) { }


(Also, just to stop anyone else pointing it out, I just noticed that my last "jump end;" in the else case is unnecessary)
Johnathan Escher
Registered User
Join date: 31 Dec 2002
Posts: 25
01-27-2003 11:14
What's wrong with having a nice language with enough features so that it doesn't have to be obfuscated?
Wednesday Grimm
Ex Libris
Join date: 9 Jan 2003
Posts: 934
01-27-2003 11:17

I'm just language-lawyering, pointing out that there are ways to get the same functionality. The more syntax and structures a language has, the more chance there is for ambiguity and "cleverness" (which is bad, as opposed to cleverness, without the quotes, which is good).

However, I do not think adding an elseif would cause the world to end.

On a semi-related note, here is something that might DESTROY THE MIND of any C programmer that dares to gaze upon it

http://catb.org/~esr/jargon/html/entry/Duff's-device.html
Sleeper Guillaume
Explorer Achiever
Join date: 8 Jan 2003
Posts: 120
01-27-2003 11:44
Well, elseif should be in the language. Until then, you can get a little closer by using:

CODE

if (foo)
{
}
else
if (bar)
{
}
else
if (baz)
{
}
else
{
}
Sleeper Guillaume
Explorer Achiever
Join date: 8 Jan 2003
Posts: 120
01-27-2003 11:46
Or you might prefer:

CODE

if (foo)
{
}
else if (bar)
{
}
else if (baz)
{
}
else
{
}
Wednesday Grimm
Ex Libris
Join date: 9 Jan 2003
Posts: 934
01-27-2003 12:23
I don't think
if () {} else if() {}
is allowed. I think it has to be
if () {} else {if() {}}
Ama Omega
Lost Wanderer
Join date: 11 Dec 2002
Posts: 1,770
01-27-2003 13:06
LOL has anyone tried else if ?

It seems since
CODE
if (boolean) statement;
else statement;


works (it does doesn't it? I have been using it....)

then
CODE
if (boolean) statement;
else if (boolean) statement;
else if (boolean) statement;
else statement;


should work.
Wednesday Grimm
Ex Libris
Join date: 9 Jan 2003
Posts: 934
01-27-2003 13:16
Please never discount the possibility that I'm insane and just makin' stuff up, then believing that it is true.
Ama Omega
Lost Wanderer
Join date: 11 Dec 2002
Posts: 1,770
01-27-2003 13:22
I have been having trouble with my scripts though, and it could be because I'm using the "if(boolean) statement;" without the {}. Although its more likely because of flawed logic on my end I think. :D

And I found it! In the cannon script in the LSLR (which I have printed out) ....
CODE
if(test ==(key)"cannonball")
die();


of course back to the subject of the thread ... uh... will find out later today around 4 heh. :)
Johnathan Escher
Registered User
Join date: 31 Dec 2002
Posts: 25
01-27-2003 14:47
In C/C++ if there is more than one line of code inside the if statement, you need the {}. I don't know if you need it in Lscript. Hmm, have to try it tonight.
Ama Omega
Lost Wanderer
Join date: 11 Dec 2002
Posts: 1,770
01-27-2003 14:59
True but "if(boolean) {.........}" is one statement (in this sense at least) in C/C++/Java. Which is why "else if" works in C/C++ .... if 'else' it does the following 'if' statement, same as if it said 'else exit();'