Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Gap in my understanding

Zephyrin Zabelin
Registered User
Join date: 10 May 2007
Posts: 153
05-15-2007 10:50
Ok.. so you can have several scripts running simultaneously - presumably they all start off when you rez the object etc? I know the scripts can communicate with each other in a couple of ways.

Now I notice when you start a new script it has a couple of event handlers defined. Presumably they are *not* supposed to be defined in every script or they'd be quarrelling with each other. So for what purpose is the multiple script feature normally employed?
MadamG Zagato
means business
Join date: 17 Sep 2005
Posts: 1,402
05-15-2007 11:03
  1. When you need to use multiple timers.
  2. When you need more memory because your script is too big.

Those are 2 that I am certain of. I am sure there are more.

Hope that helps!
_____________________
RobbyRacoon Olmstead
Red warrior is hungry!
Join date: 20 Sep 2006
Posts: 1,821
05-15-2007 11:10
I assume that you are talking about multiple scripts in a single object, correct?

In addition to what MadamG gave as an example, you might use a seperate script to handle communication. Several of the communication methods have built-in delays, and this (seemingly arbitrary) delay can have a dramatic negative effect on an interactive object, so you may choose to use link messages to pass email or instant message information to a "queue" script. This allows your main script to continue running while the other script suffers from the comm delay.

Another common use for multiple scripts is modularity... You may want a seperate script to keep track of persistant data for instance, since as MadamG pointed out above each script is limited in the amount of memory it can consume, and that memory is shared between the code itself and all of the data that it uses. Using multiple scripts allows you to work around that memory limitation somewhat.

There are surely many more useful examples, many of which can be found on the LSL wiki, but that ought to give you an overview on some of the reasons that multiple scripts can be useful.

.
_____________________
Shyan Graves
Registered User
Join date: 10 Feb 2007
Posts: 52
05-15-2007 11:16
- easier maintenance
- reusability
- modularization
- enhancement of an object (new function) toan object that has already a script running,
which is not changable by you

That and what MadamG said are the purposes for me ;-)
Zephyrin Zabelin
Registered User
Join date: 10 May 2007
Posts: 153
05-15-2007 11:24
I see, thanks. Do most people keep all the event handlers on one script of a multi-script object, or is it fine to spread them amongst the scripts. And can an event handler on one script directly call a function you defined on another (on the same object of course), or are the inter-script messages the only way?
Milambus Oh
Registered User
Join date: 6 Apr 2007
Posts: 224
05-15-2007 12:03
It would depend on what the scripts are doing. If the events are linked and acting upon the same data it is much easier to keep them in the same script, else you will have to be continually sending that data back and forth via linked messages.

No, I don't believe you can call a function in another script, but you could send a link message which the listen event would call the function. You can also use llSetScriptState to directly effect the state of another script in the same object.
Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
05-15-2007 12:18
I use multiple scripts frequently when implementing fuzzy logic, as it's the most fluid way to go about a voting based AI. For example in an A-life AI:


Script 1- Hunger meter, tells the animal how hungry it is and it's desire for foor
Script 2- Social Meter, tells the animal how close it is to it's own kind and wether it wants to be closer or farther away
Script 3- Prey Meter, tells the animal how close it is to a preadator and if it should react or not.


each script will vote it's desire to do an action on a set scale. Due to the event driven nature of SL, this is not possible to do effectively with a single script.


Other uses I have found are for multiple levels of security being able to simultaneously be in place: a list of people only added in by the owner through /say, a list of people on a note-card, a list of people who have paid a set price, etc. it's easier to have one authenticating script for each type in place which the user can toggle between on/off states, which is then handled by one more script, than it is to try and cram all these layers into one script.

there are probably dozens more specific application uses for having multiple scripts as well.
_____________________
My SLExchange shop

Typos are forgiven; desecrating the english language with reckless abandon and necrophilic acts is not.


The function is working perfectly fine. It's just not working the way you wanted it to work.
Zephyrin Zabelin
Registered User
Join date: 10 May 2007
Posts: 153
05-15-2007 15:01
Are there user-defined attributes on an object that can be accessed by all the scripts? Using this example of hunger or social scores, is it possible that a script handling the social settings can refer to the hunger score on some sort of superglobal that all scripts can see? You may recognise that I am thinking of the Attributes on an object in The Sims, which of course any BHAV on any object can access.
Sys Slade
Registered User
Join date: 15 Feb 2007
Posts: 626
05-15-2007 15:42
There are no super globals as such, but various things can be used to pass data around.
The most obvious one is llMessageLinked, which sends a message to all prims or a specific prim in the set. Sending a linked message to the same prim that contains the script allows all the scripts in that prim to pick up the message.
Other ways include setting certain properties of a prim, such as colour/rotation/etc and using the state of those properties as a message.
_____________________
Send me the last 4 digits of a valid SSN, I'll verify you are who you say you are, even if you aren't.
Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
05-15-2007 21:33
From: Sys Slade
There are no super globals as such, but various things can be used to pass data around.

Other ways include setting certain properties of a prim, such as colour/rotation/etc and using the state of those properties as a message.



also a somewhat niche use is altering the description text of an object as a means of persistant storage of data that can be written to.
_____________________
My SLExchange shop

Typos are forgiven; desecrating the english language with reckless abandon and necrophilic acts is not.


The function is working perfectly fine. It's just not working the way you wanted it to work.
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
05-16-2007 00:18
And you can also use the "hidden face" trick for small amounts of data.
_____________________
I'm back......
Zephyrin Zabelin
Registered User
Join date: 10 May 2007
Posts: 153
05-16-2007 00:19
Hehe so it's a case of being inventive with the workarounds :D Thanks very much everyone, this should get me going.