Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Limit to the # of else if statements?

Jeff Caldera
Registered User
Join date: 12 Jun 2004
Posts: 11
01-07-2006 10:34
I seem to have run across a weird quirk in LSL that I'm curious if anyone else has noticed and/or found good work-arounds for. I have an if block in one of my scripts that I needed to put 31 else if's in. On compiling, I got a syntax error, and after commenting out various sections of the code to try to find a mistake, I found instead that the code would compile only as long as I had 18 or fewer else if statements in the if block. I even tried putting the rest of my else if statements in an else if (TRUE) block, to try to make a work-around, and that didn't compile either.
Introvert Petunia
over 2 billion posts
Join date: 11 Sep 2004
Posts: 2,065
01-07-2006 10:38
From the LSL Wiki:

Note: Only up to 23 else statements may be in a conditional chain. (a total of 24 conditionals: 1 if and 23 elses) Any more, and a syntax error will occur when the script is saved/compiled. However, a workaround to this is to nest conditionals, or, if that's not possible, split the conditional chain into a series of distinct if statements: at the end of each if(){} block, put a jump or return as the last statement so that the remaining if statements that would have otherwise been "else if" statements are skipped.
It wouldn't surprise me if that "23" was not carved in stone.
Kenn Nilsson
AeonVox
Join date: 24 May 2005
Posts: 897
01-07-2006 12:30
Just embed a couple of those else-if statements and you'll be good again.
_____________________
--AeonVox--

Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms chasing ghosts, eating magic pills, and listening to repetitive, addictive, electronic music.
Jeff Caldera
Registered User
Join date: 12 Jun 2004
Posts: 11
01-07-2006 16:56
Thanks, I've got a good workaround working now.