CODE
integer lbl;
jump lbl;
@1;
<code>
return;
@2;
<code>
return;
@3;
<code>
return;
etc etc
The Wiki doesn't specify if it only allows literals. Does anyone know if this is possible? I'm not at home to try it out atm.
Thanks.
These forums are CLOSED. Please visit the new forums HERE
Can a jump label be a variable? |
|
|
Russell Hansen
Texi pets are here!
Join date: 11 Apr 2006
Posts: 107
|
09-27-2006 16:45
I'd like to be able to use a variable for a jump label, such as
CODE integer lbl; The Wiki doesn't specify if it only allows literals. Does anyone know if this is possible? I'm not at home to try it out atm. Thanks. _____________________
Russell Hansen - Texi Pet Creator
Texi Pets, your SL Companions and Personal Assistants http://texipets.com |
|
Gerami Fizz
That Guy
Join date: 15 Jun 2005
Posts: 88
|
09-28-2006 06:27
Whoa. I didn't even know there was a jump keyword... I just lost 10 points of LSL cred.
...but I've never needed it, so I get those 10 points back ![]() Anyhow, seeing as how I didn't know it existed until about 75 seconds ago, I can't say I've tested it. Judging solely from the Wiki, my first reaction would be "it looks like you're defining a variable name, and variable names can't be variable." Can someone confirm/deny? |
|
Zeera Xi
Real Join Date: Mid '05
Join date: 21 Sep 2006
Posts: 54
|
09-28-2006 09:50
I dont know what exactly you are trying to do but I hardly think so. Jump is just a flow command that changes the flow from its point to the label specified after it that is somewhere else in the code.
|
|
Don Misfit
Registered User
Join date: 1 Jun 2006
Posts: 60
|
09-28-2006 11:22
Quick answer is No, you cannot define a jump with a variable. Jump locations are processed when the script is compiled, so the compiler will not take a variable as part of a jump statement.
Long answer: Jumps are baaaad. Only one condition (that comes to mind) where a jump is *almost* necessary in LSL is to break out of a for or while loop, since LSL lacks a break statement (but only *almost* necessary, as there are other ways to deal with that). Any other use of jump *should* be replaceable with better code structure / logic. Don |
|
Russell Hansen
Texi pets are here!
Join date: 11 Apr 2006
Posts: 107
|
09-28-2006 15:37
Yeah I didn't think it would work. What I was trying to achieve was a simpler "CASE" construct than multiple "IF" statements, particularly because the cases I'm testing is a simple sequential list of numbers, so
CODE jump lbl; would be much easier to code, more memory efficient (maybe) and perform better than CODE if {lbl == 1} then Oh well, back to living with the limitations of LSL _____________________
Russell Hansen - Texi Pet Creator
Texi Pets, your SL Companions and Personal Assistants http://texipets.com |
|
Aakanaar LaSalle
Registered User
Join date: 1 Sep 2006
Posts: 132
|
09-28-2006 18:34
not to be lethargic.. er.. ok.. yea maybe that is the intent.. I still remember the first computer I ever looked at.. TRS-80 from RadioShack.. no floppy drive, we saved code on a cassette tape inside a cassette recorder that plugged into the computer..
and code was like CODE
Jump is a throwback to the good old days.. The days before television when we all used to gather round and watch paint dry.. ![]() |
|
carol Wombat
Registered User
Join date: 29 Jan 2006
Posts: 16
|
09-28-2006 19:24
Hi Russell,
Your problems don't end there. Because of the primitive nature of the lsl compiler and the 16K limit, we tend to run into stack size problems. Good programming says one entry and one exit point for each function, but in lsl it is often necessary to break your code up so it exits as soon as the job is done. Nested ifs can add too much to the compilers stack! Here is a fragment to select some action: CODE
|
|
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
|
09-29-2006 09:27
I looked at this comment about nested if's and thought... no, can't be right.
So, I went and tested. CODE open() And the same script, but without the if ... else and with returns. Outputs as follows, returns version first: CODE
Then the if...else version CODE
Looks to me like if.... else is more efficient, which is what I would have expected. _____________________
|
|
Jigsaw Partridge
A man of parts
Join date: 3 Apr 2005
Posts: 69
|
09-29-2006 10:09
It is of course more efficient, plus more elegant, readable, maintainable etc, to use an if/else construct rather than sequential if blocks. The problem, as carol said, is that the LSL compiler frequently barfs on them, in large scripts. For that reason I tend to avoid them now, for anything more complicated than a single 'else'.
|
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
09-29-2006 10:25
Yeah, try an if-else switch for say 20-30 commands. It's not a run-time thing, it's a compile-time thing, the compiler will barf and throw an error. I've had to break things up into multiple "upper level" if-elseif checks, and inside each is a "lower level" if-elseif check.
Switch-case, arrays, function pointers... mmmmm. |
|
Ralph Doctorow
Registered User
Join date: 16 Oct 2005
Posts: 560
|
09-29-2006 10:35
What Ziggy said.
I've had it barf on 7 levels, but it depends on the rest of the code in the script. (IMNSHO this is a crock) |
|
Haravikk Mistral
Registered User
Join date: 8 Oct 2005
Posts: 2,482
|
09-29-2006 11:44
Aren't jump instructions better for loops if you know what you're doing? I've always found that something like:
CODE @loop; Will run faster (and use less memory) than a comparable for or while statement. _____________________
Computer (Mac Pro):
2 x Quad Core 3.2ghz Xeon 10gb DDR2 800mhz FB-DIMMS 4 x 750gb, 32mb cache hard-drives (RAID-0/striped) NVidia GeForce 8800GT (512mb) |
|
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
|
09-29-2006 12:06
What Ziggy said. I've had it barf on 7 levels, but it depends on the rest of the code in the script. (IMNSHO this is a crock) You can add to it in more complicated if() contructions the jump calls can plain fail to execute. i.e. if you try to go around if-else limits with if() { stuff(); jump continue; } if() { other_stuff(); jump continue; } // etc @continue; // go on ... it will still walk through remaining if() calls in some situations :/ |
|
Don Misfit
Registered User
Join date: 1 Jun 2006
Posts: 60
|
09-29-2006 13:18
Aren't jump instructions better for loops if you know what you're doing? I've always found that something like: CODE @loop; Will run faster (and use less memory) than a comparable for or while statement. Hmmm... well, I have no idea about performance comparisons with LSL, but *in general* I would have to say that is entirely compiler dependent... There is no logical reason that should execute faster, or use less memory, than: CODE while ( x-- > 0 ) { doSomething(x); }Edit: Figured I'd test it out... for a 2500 count loop: CODE "jump" method: 6.526 seconds |
|
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
|
09-30-2006 00:47
Yeah, try an if-else switch for say 20-30 commands. It's not a run-time thing, it's a compile-time thing, the compiler will barf and throw an error. I've had to break things up into multiple "upper level" if-elseif checks, and inside each is a "lower level" if-elseif check. Switch-case, arrays, function pointers... mmmmm. Try the bottom of http://lslwiki.com/lslwiki/wakka.php?wakka=ifelse You can have a max of 23 else's in the chain otherwise there's an error. I've had scripts that hit that limit before, but I rather suspect n if...else statements with 23 else's in a chain in each is even more memory efficient than 24n single ones with a return. Much more than 24 and I'm starting to wonder what you're doing, and could it be done in a better way. I recently made a dance machine for someone that will take 60(+) dances and 40+ dancers. There's about 6 if...elses altogether. Sure I could do it some other way with huge chains of if's, but it's much neater this way. _____________________
|
|
Aakanaar LaSalle
Registered User
Join date: 1 Sep 2006
Posts: 132
|
09-30-2006 01:18
if a lot of the code for the different cases are the same with just different things.. hrm.. that's not quite clear.. Let's say for an example that you had a bunch of animations and you want to trigger the right one..
You could do something similar to this: CODE
You can see what i'm doing there.. it cuts down on the if-elses, and makes the code a bit easier to read.. It may not cut down all the if-else's you need, depending on how many different things you want made available, but if you group the like code together you could use this same trick for several groups, and really save a lot of code. Just an idea |
|
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
|
09-30-2006 05:07
That's basically how I did a big chunk of it. To handle more than 12 dances and a few other things there's a couple of extra bits but that was very much the point I was making... There are times where you need long chains of if... else statements, but a lot of the time things like lists etc. can make your life easier.
_____________________
|
|
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
|
09-30-2006 08:21
Much more than 24 and I'm starting to wonder what you're doing, and could it be done in a better way. Nested dialog-driven control menu, mainly, especially when combined with support for commands issued on predefined channel. It can be trimmed with list look-ups and such like mentioned, but there's only so much that can be offloaded in the lists... |
|
grumble Loudon
A Little bit a lion
Join date: 30 Nov 2005
Posts: 612
|
09-30-2006 13:12
I've found it's faster to get the string lenght and do a series of if x = n statements to presort the string compare.
CODE
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
10-01-2006 13:04
I usually find that if I need more than 10 or so if-else conditions my code can be better organized by using a list search, function calls, or even splitting into multiple scripts. That limit of 23 is awefully funny though. I just really can't think of any sane reason there would have to be a limit.
|
|
Escort DeFarge
Together
Join date: 18 Nov 2004
Posts: 681
|
10-01-2006 14:05
_____________________
http://slurl.com/secondlife/Together
|
|
Russell Hansen
Texi pets are here!
Join date: 11 Apr 2006
Posts: 107
|
10-01-2006 15:28
That seems to be an oft quoted article that says nothing that hasn't been said for 20+ years anyway.
It's as bad as saying Microsoft Access is a bad tool. There's nothing wrong with it per-se, the problem is it makes powerful tools accessable to everyone. It's like giving a chainsaw to a 5 year old. Anything powerful is dangerous if you don't use with respect. The grid griefings show how LSL is a powerful enough tool in the wrong hands. The problem is, it is at the level of BASIC on the Commodore-64. We have to live with it's limitations and create in a non-perfect world. Unrolling loops, functions that spread over multiple events etc etc. Just look at some of Strife's thread on saving memory (/54/c1/88658/1.html) There is nothing wrong with Jumpas such, and when used for forward jumps only, is relatively safe. Either way, it's not the solution to my problem. I'm checking for commands and running multiple different procedures for each command, so list searches don't help either, as somewhere along teh way you have to say "if this command run that code". With no type of pointer de-reference facility to parameterize calls, I'm stuck with the multiple IF statements over multiple scripts if I run out of memory. Nothing I'm not used to doing, just was trying to find more fficient ways of doing things in LSL. All of the comments are duly noted for use where relevant, and thanks for the feedback. _____________________
Russell Hansen - Texi Pet Creator
Texi Pets, your SL Companions and Personal Assistants http://texipets.com |
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
10-02-2006 09:56
Much more than 24 and I'm starting to wonder what you're doing, and could it be done in a better way. I was waiting for someone to say that ![]() |
|
ScriptScavenger Lei
Registered User
Join date: 3 Sep 2006
Posts: 14
|
if, else if ,else
10-02-2006 20:01
quite honestly why is there an "else if"
if im string "if"s and ending with "else" do i even need that ? and even if i require more than 23 "if"'s and an "else" (again what are u doing ? ) especialy in the case of voice commands you can always slap it in a second script as multiple scripts in one object run simotaniously. furthermore i belive the intent of a jump is foward movement and a return rearward move ment. The whole "State " process should remove the necisity as u can simply change state i belive the most expidient methods would be nesting and listing when posible. not that ive run into it but there is a hypothetical 1024k limit to a script (dont think ive seen anything that big either ) its probably a better idea to run multiple small scripts than one catch all. |
|
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
|
10-03-2006 11:01
I use jumps mostly when the script structure is too complex to do nicely with if's alone. I usualy use them so i do not have to duplicate code.
I've gotten in the habbit of writing optimized code so i use them often. When optimizing code it is best to only optimize what you grok. It is ill advised to try and optimize an aspect of your code you don't grok. Recently i've been using jumps to get around the compilers limits. for long if/else if blocks where the compiler chokes... Here are some ESL macro's i use... CODE #define concat(a, b) a##b CODE if (a) CODE if (a) _____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river. - Cyril Connolly Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence. - James Nachtwey |