Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Splitting my script

Marcel Flatley
Sampireun Design
Join date: 29 Jul 2007
Posts: 2,032
02-19-2008 01:07
Since a few days I have been busy with a script which works like a charm up to now. But it is getting rather long, which makes it hard to keep the overview.

Now I do see in other products that people use more then 1 script, which would make it a lot easier for me. I would like to have 1 script with the functions I wrote, and 1 script responding to the events for example. In the environment I usually script in, it would be called a script library.
But I have no clue how to do that. Can I call a function from another script in the same prim, or does all the traffic between 2 scripts need to be done with llSay or llWhisper commands on a specific channel?

Seems like an easy question, but is enough a bother to me to ask it :-)

Greetings, Marcel
_____________________
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
02-19-2008 01:14
Generally you'd use llMessageLinked() and the 'link_message' event handler rather than chat commands, if the scripts are in the same prim or object. But in terms of mechanics, it is very close to chat commands: message based rather than direct-call. The definitions of functions, states, and globals are local to its script file.

Think of it as having to do absolutely everything over UDP, except that message delivery is ALMOST sort of half guaranteed in a way--but not quite if you have a lot of them queuing up (link message events queue a maximum of 64 for each receiving script before getting lost). ;)
Marcel Flatley
Sampireun Design
Join date: 29 Jul 2007
Posts: 2,032
02-19-2008 01:37
Which would make splitting up my script in multiple parts only less effective I guess :-) Will look into llMessageLinked() though as to get a general idea in what it can do, this script language is rather new to me, though I am catching up.

Thanks for the fast reply!

Marcel
_____________________
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
02-19-2008 07:40
Right - splitting scripts can be great, but it's rarely simpler because instead of a synchronous action (calling a function) you have asynchronous action (you send a message and that either performs some action or causes a reply message to be sent).

There isn't any way to do the equivlant of a library function in LSL. I keep a library of code snippets and functions that I copy/paste into new scripts.

If a script is hard to read, splitting it into multiple scripts rarely makes it easier to read, unless simply being forced to re-architect the thing causes you to organize it better -- but you can do that without having to split the scripts.

We generally use multiple scripts for these reasons:

A) the functions are intrinsically different and unrelated to begin with
B) we're running out of memory for one script
C) we want to avoid the delays caused by certain functions in a main script and delegate them to helper scripts.
D) a script can have permissions for only one avatar at a time but the object needs to handle multiple avatars (e.g., dance balls & sex beds)

Case C is usually a bad idea; the delays were added to discourage us from overusing a function, and working around it is likely to cause lag. However, there are valid cases, such as when the functions are rarely used, but when they are we need them to happen in rapid succession.