Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

goto ABC

Tarak Voss
Meanderer
Join date: 14 Oct 2006
Posts: 330
06-21-2007 20:28
In Basic one could say goto line number (how wonderful that was). But how do we do it in LSL.

I have a point in a script where three things can occur (1) restart script, (2) continue script and (3) jump a long way ahead to another portion of the scrip.

How do I do the jump it is too far for an IF statement (well too clumsy).
DoteDote Edison
Thinks Too Much
Join date: 6 Jun 2004
Posts: 790
06-21-2007 20:42
One way... you turn the line you want to "go to" into a function. Then, whenever you need to "goto" it, you call the function. In the script below, anytime you call "customFunction();", that function will execute.

customFunction() {
llOwnerSay("You rang?";);
}

default {
touch_start(integer num) {
customFunction();
}
}


I know it's not a goto statement. There are other ways to do whatever you need to do. Maybe you could post a brief description of why you need a "goto" and we can help you figure a better method to get there.
ed44 Gupte
Explorer (Retired)
Join date: 7 Oct 2005
Posts: 638
06-21-2007 22:04
Three things:

1. Use states - not so many things to if about.

2. Break your code into more functions. They sit before the "default" statement. LSL only uses "if" for conditional branching.

3. Use early return statements as part of each "if". See my sticky post above.
Tarak Voss
Meanderer
Join date: 14 Oct 2006
Posts: 330
06-21-2007 22:20
From: ed44 Gupte
See my sticky post above.


Thanks for this but what is a "stiky Post' and how do i access it?
Tarak Voss
Meanderer
Join date: 14 Oct 2006
Posts: 330
06-21-2007 22:22
I'm a bit thick here but can you name your own states - or can you nly use standard named states.

:)
Teddy Qinan
Registered User
Join date: 10 Mar 2007
Posts: 34
06-21-2007 22:24
From: Tarak Voss
In Basic one could say goto line number (how wonderful that was). But how do we do it in LSL.


Say What!?! Forget basic dude, basic didn't even have events! :)
Tarak Voss
Meanderer
Join date: 14 Oct 2006
Posts: 330
06-22-2007 00:49
Hmmm - but basic could write itself and amend its own program as you used it (kind of self repair) and if you had a Commodor 64 you could utilize the memory area of the language twice. - Are the dream times - mind you with 64K of ram and a 10 MB hard disk - it is hard to image now - but it beat punch tape. :)
Object Pascale
moshi moshi
Join date: 27 Jan 2007
Posts: 648
06-22-2007 01:46
Goto has been frowned upon since the sinclair and commodore era because it tends to produce unreadable, unmaintainable spaghetti code. you want to utilize the same memory area twice (or an infinite number of times)? welcome to the world of functions and states.
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
06-22-2007 02:03
From: Tarak Voss
Hmmm - but basic could write itself and amend its own program as you used it [...]
As a former LISPer, don't get me started! (longs for closures, the Meta-Object Protocol, ... and now we debate the utility of function-typed variables, arrrgh!)

But to handle a couple questions: Yes, one can define one's own states. In addition to:
default
{...
}
you can have:
state some_other_state
{...
}
and switch to it with a statement like:
state some_other_state;
from inside an event handler (not so nicely, though, from inside a function).

If you really long for "GOTO", the LSL moral(?) equivalent is:
jump destination;
...
@destination;

And a "sticky" is a posting that stays at the top of the forum list, helpfully adorned with a red "Sticky:" label.
Tarak Voss
Meanderer
Join date: 14 Oct 2006
Posts: 330
06-22-2007 19:02
Thanks for all that - I was talking in jest about BASIC - I know things have moved on :))