There is a simple way to solve this problem if we enhance LSL by introducing a new directive: import. To avoid to introduce new problems too, however, we have to define some constraints. Here is my proposal.
DIRECTIVE SYNOPSYS
import(data);
where 'data' is a string containing the name of a script
CONSTRAINTS
1. 'data' MUST be in the SAME object inventory that contains the script containing the import directive
2. 'data' can contain ONLY typed or simple assignment statements, that is, no declarations and no instructions
3. import MUST precede the default{} statement, even if it is not necessary that it be the first statement in code
Let's analyse the constraints. The first one avoids that you can include code from other inventories, which may create dangerous side effects and be difficult to maintain and manage. The second one avoid that you can use that directive to import executable code. Avoiding declarations make selfcontained the data script. More freedom may generate side effects and may make more difficult to maintain all scripts aligned. The third one allows to write default value before import. In fact, if data is not available in the object inventory, import is ignored: no error or warning is issued. There is another directive that we can use if data is a mandatory script: require.
require(data);
works as import, but if data is not available, the script is NOT executed.
Let's make some example. Here is a classic script:
CODE
string welcome = "Welcome!" ;
default
{
state_entry()
{
llSay( 0, welcome);
}
}
Let's create a data script for welcome and call it "hi":
CODE
string welcome = "Welcome!" ;
and change script accordingly:
CODE
require("hi");
default
{
state_entry()
{
llSay( 0, welcome);
}
}
Now, I can use the welcome script in another object and use a different data script as
CODE
string welcome = "Benvenuto!" ;
or
CODE
string welcome = "Aloha!" ;
I could also write my scripts in another way:
CODE
welcome = "Welcome!" ;
and change script accordingly:
CODE
string welcome = "Hi!";
import("hi");
default
{
state_entry()
{
llSay( 0, welcome);
}
}
In this case I have a default string, so I will not specify the type in the data script, and I will use import rather than require. I could also use
CODE
welcome = "Welcome" ;
and
CODE
string welcome = "Hi";
import("hi");
welcome += "!" ;
default
{
state_entry()
{
llSay( 0, welcome);
}
}
Dario de Judicibus