|
Bartiloux Desmoulins
Think Kink? Think Bart!
Join date: 27 Sep 2005
Posts: 121
|
09-03-2007 11:28
Now that I've somewhat gotten the hang of scripting basics I have a question about what I'm thinking is a somewhat more advanced techique. I have purchased a number of items that contain more than one script, all in the same prim. Based on their names, the scripts seem to do different things. What I'm wondering is this... What are the pro's and con's of separating tasks into mutliple scripts as opposed to just having a number of subroutines all within the same script? Right off the bat I can think of one benefit, and that would be timers. If you have need to have two events triggered based on a time, but the time intervals are not related I can see where separate scripts would be handy. Surely there are other applications for this techique. I'd appreciate hearing your thoughts regarding when to use (and not use) mutliple scripts in a single prim. Warmest regards, Bartiloux Desmoulins
|
|
Matthew Dowd
Registered User
Join date: 30 Jan 2007
Posts: 1,046
|
09-03-2007 11:36
The main reason is memory - a script only has a memory heap of 16K - that includes all the code and the variables, plus parameters are passed by copy in function calls!
Matthew
|
|
Ravanne Sullivan
Pole Dancer Extraordinair
Join date: 10 Dec 2005
Posts: 674
|
09-03-2007 11:52
Another good use for multiple scripts is for reuse of commonly used functions. If you have a script that turns on the light parameter of a prim and varies its intensity you might set that as a stand alone script that could controlled from some other script and say yourself the time of incorporating the function in your base script and having to deal with it while debuging if something does not work as expected.
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
Another reason...
09-03-2007 12:01
since certain calls have a built in delay, it's easier to put those functions in a seperate script and call the script with llMessageLinked. in this way the main script doesn't have to pause while it does the delayed function, but that function still occurs.... this technic can also be used to rapidly fire off multiply delay causing events without actually being delayed by them.... for an example, wiki.secondlife.com/wiki/LlInstantMessage
|
|
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
|
The downside
09-04-2007 04:57
So, there's always a trade-off, right? The thing is, every "running" script in every prim adds a tiny bit of lag to the sim. I know that's daft, but it's the way the sim scheduler works. (There's a thread somewhere in this forum started by the incomparable Lex Neva  with statistics from some very careful measurements that show just how much each script contributes.) Amazingly, the script doesn't even have to have an active event handler; just an empty default state_entry (the minimum to make the compiler happy) is enough to make that script get a little time-slice forever more, as long as the "Running" box is checked. That's especially annoying for scripts that only set prim properties (like particles or texture animation) and then never do anything again. For those, it's good form to either remove the scripts or set them not running once they've executed.
|