Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Multiple Scripts questions

Wyatt Burton
Registered User
Join date: 11 Jan 2007
Posts: 49
12-08-2007 19:47
I can't find clear answers to the following questions I have:

1) Can there be multiple scripts inside the same prim? If yes which one's default state is executed first?

2) Is llMessageLink the only way multiple scripts communicate with each other inside the same prim.

3) Are global variables the only ones that retain permanently their values (until reset) when a prim is not active. Can you have globals in multiple scripts of the same prim?

4) Is a reset only done when one saves or manually resets to clear the global variables. Must each script be reset individually?


Any answers or links to answers would be appreciated. Thank you.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
12-08-2007 23:33
From: Wyatt Burton
1) Can there be multiple scripts inside the same prim? If yes which one's default state is executed first?

yes, and whichever compiles fastest/first... effectively they are simultaneous
[technically, tiny slices of each one would be executed in the order the sim finds them (possibly the same order they are listed in the prim)]
From: someone
2) Is llMessageLink the only way multiple scripts communicate with each other inside the same prim.

they could possibly communicate other ways by modifying and monitoring a prim property, or any of several other things, but link messages will usually be your best bet
From: someone
3) Are global variables the only ones that retain permanently their values (until reset) when a prim is not active. Can you have globals in multiple scripts of the same prim?

essentially, yes, variables declared in an event handler clear when the handler is exited. globals don't (unless you do something to clear them). you can have as many globals as you can fit in each script (there are other possible static storage options like prim properties, whith their own cost and benefits)
From: someone
4) Is a reset only done when one saves or manually resets to clear the global variables. Must each script be reset individually?

script resets occur:
- these will reset a single script
when compiling
when called from the script (llResetScript)
when called from another script (llResetOtherScript)
when called by the user from the script window (reset)
-this may reset multiple scripts
when called from the tools menu by the user (reset selected script, or reset all scripts in selection)
and sometimes (but not always) when a sim is reset/restarted

global variables can be cleared just like any other variable, so a reset is NOT the only way to do it.

for reference:
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
12-09-2007 08:33
I want to elaborate on one thing. In LSL, you cannot usually rely on things to happen in the order you might assume they will. So, you cannot rely on one script's default state to start first.

Likewise, you can send message A followed by B, and B can arrive before A.

Be careful of your assumptions.
_____________________
So many monkeys, so little Shakespeare.
Okiphia Rayna
DemonEye Benefactor
Join date: 22 Sep 2007
Posts: 2,103
12-09-2007 13:05
If you want things to execute in proper order, as stated , don't expect them to just happen.

I'd recomend having the first one do something first that triggers the next one(s) and so on so that you get the right order. Otherwise you might have it going backwards

(Saying "I'm ready to fly" before it is actually ready to fly for example)

But I'm not much of a scripter.... I use states, but thats probably not the best way
_____________________
Owner of DemonEye Designs Custom Building and Landscaping
Owner and Blogger, Okiphia's Life
http://okiphiablog.blogspot.com/
Squirrel Wood
Nuteater. Beware!
Join date: 14 Jun 2006
Posts: 471
12-10-2007 00:03
Note also that global variables declared in one script are *not* known to other scripts in the same or other prims/objects unless they are declared in those scripts and the variable content is somehow communicated.

In other words:
Global variables are only global and known in the script they are declared in.
Wyatt Burton
Registered User
Join date: 11 Jan 2007
Posts: 49
12-10-2007 16:52
Thanks everyone, replies were helpful.