Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

external Functions

Gruntos Baxter
Registered User
Join date: 15 Jan 2007
Posts: 20
02-16-2007 13:47
is is possible to have a call to a external function. What I mean is I want to write some common code and drop it in to an object along with the default

I tried to create a script with just a few functions in but it needed a state descriptor adding this got the code to compile but nothing

even thought I have 2 scripts attached to an object the call to function in the other script caused a not in scope message.


regards
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
02-16-2007 14:37
From: Gruntos Baxter
is is possible to have a call to a external function. What I mean is I want to write some common code and drop it in to an object along with the default

I tried to create a script with just a few functions in but it needed a state descriptor adding this got the code to compile but nothing

even thought I have 2 scripts attached to an object the call to function in the other script caused a not in scope message.


regards


All scripts must have a default state.

Sort of.
Your script must be self contained, i.e. must contain any functions it wants to call.
However thats only half the story. You can request data from another script in the same object using linked messages, or further a field using email or http.

In your above case you would need to send a linked message to the second script detailing what you wanted, and passing it any parameters it needed


Heres a rather trivial example
Script 1
CODE

integer GETDATA = 9000;
integer RESULT = 9001;

default
{
state_entry()
{
}

touch_start(integer total_number)
{
key id = llDetectedKey(0);
string parameters = (string)id;
llMessageLinked(LINK_THIS, GETDATA , parameters , NULL_KEY);
}

link_message(integer sender_num, integer num, string str, key id)
{
if(RESULT == num)
{
llOwnerSay("Got a result :- " + str);
}
}
}



Script 2
CODE

integer GETDATA = 9000;
integer RESULT = 9001;

default
{
state_entry()
{
}

link_message(integer sender_num, integer num, string str, key id)
{
if(GETDATA == num)
{
key id = (key)str;
string Name = llKey2Name(id);
llMessageLinked(LINK_THIS, RESULT , Name , NULL_KEY);
}
}
}


HtH
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
02-16-2007 18:30
this is actually an ironic point about lsl , the generic explination provided by linden labs is a bunch of tiny scripts that users can add into an object to provide big functionality

with no includes...

thats ok tho becuase their VM cant really handle a ton of tiny scripts, each one nomatter if its a one liner or a opus gets the same sim cpu time anyways, even if its not active
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
02-17-2007 07:20
The no includes is only a problem if you use the SL LSL editor rather than a 'proper' programmers editor such as Scite-Ez.
Gruntos Baxter
Registered User
Join date: 15 Jan 2007
Posts: 20
02-17-2007 16:26
I'll play with the Linked message seams a long way to go just to call some common code

it wold be nice to have some control over debugging like step, var inspection, and watch etc.
like gdb in xemacs
Oh well


Regards