Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

sharing variables between scripts?

QueenHeather Hancroft
Registered User
Join date: 26 Sep 2008
Posts: 20
10-15-2009 10:15
Hi,

basically im using multiple scripts in 1 object
and i need to check variables from a script its not stored/defined in.

is this even possible or how would i go about it?
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
10-15-2009 10:36
You can store variables in a prim's description. Let one script set the description and another one read it.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Kayaker Magic
low carbonated footprint
Join date: 11 Sep 2008
Posts: 109
10-15-2009 11:06
You can llMessageLink between the scripts to send data back and forth.
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
10-15-2009 11:30
From: Rolig Loon
You can store variables in a prim's description. Let one script set the description and another one read it.
Persnickety correction: you can store VALUES in a prim's description. ;)

There are other places where you can stash values, such as parameters for a prim face that's not visible. (For example, if your object is a sphere, you can make it hollow, and then it has another face. Every face has color and alpha values that you can set and get.) Using tricks like this makes the script less general-purpose, of course.

And as mentioned above, llMessageLinked(), which is the main way of passing information between scripts in an object.
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
10-15-2009 12:13
From: Lear Cale
Persnickety correction: you can store VALUES in a prim's description. ;)

Touché! .... That's what I get for typing before finishing my coffee. :p
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
QueenHeather Hancroft
Registered User
Join date: 26 Sep 2008
Posts: 20
10-15-2009 12:57
objectdesc is good idea like hippotech does,

im trying to use linked msgs now, what i need help with is. sending more than 1 peice of info.

right now im only sending "tenantshome" but i would also like to include thier name in the string

tenantshome|queenheather hancroft

i need to know how to seperate the two when i recieve them

link_message(integer sender_num, integer num, string msg, key id)
{
if (msg == "tenantshome" && rented == TRUE)
{
}
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
10-15-2009 13:22
Your friend is llParseString2List, as in

list myNewList = llParseString2List(msg,["|"],[""]);.

Then you pull your two variables, tenantshome and avName, out of the new list with llList2String, as in

string tenantshome = llList2String(myNewList,0);.

See http://lslwiki.net/lslwiki/wakka.php?wakka=llParseString2List and http://lslwiki.net/lslwiki/wakka.php?wakka=llList2String.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Jack Abraham
Lantern By Day
Join date: 11 Apr 2008
Posts: 113
10-15-2009 13:24
Take a look at llParseString2List and llParseStringKeepNulls.

EDIT: And I'm beaten to the punch. : )
QueenHeather Hancroft
Registered User
Join date: 26 Sep 2008
Posts: 20
10-15-2009 13:50
problem i got now,
i check for alot of linked msgs, and usually its just oneword so unnecasery to split atall.

if (msg == "tenantshome" && rented == FALSE)

this line wont work because it includes more info than just "tenantshome" in the string.

so how do i go about this

must i seperate every string i recieve before hand because in that case ill have to compare if llList2String(myNewList,0); == MSGIMLOOKINGFOR on every single linkedmessage i recieve

or would it be better to check if tenantshome is "in the string" i recieve , before splitting the msg so i dont have to do it everytime ??? thats what i need to know how to do

i hope people know what i mean
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
10-15-2009 14:26
Yup, that's exactly what you do.

CODE

link_message(integer sender_num, integer num, string msg, key id)
{
list templist = llParseString2List(msg,["|"],[""]);
string Var1 = llList2String(templist,0);
if (Var1 == "tenantshome" && rented == TRUE)
{ // blah blah blah
}
}


ETA: You could compact all of this to

CODE

link_message(integer sender_num, integer num, string msg, key id)
{
if(llList2String(llParseString2List(msg,["|"],[""]),0) == "tenantshome" && rented)
{ // blah blah blah ....
}
}
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Beverly Ultsch
Registered User
Join date: 6 Sep 2007
Posts: 229
10-15-2009 15:21
Or check the easy stuff first.

Something like

CODE

link_message(integer sender_number, integer number, string message, key id)
{
if(message == "simpleMessage1")
{
//do stuff
}
else if(message == "simpleMessage2")
{
//do stuff
}
else
{
list complexMessage = llParseString2List(message, ["|"], []);

if(llList2String(complexMessage, 0) == "tenantshome" && rented == TRUE)
{
// do more stuff
}

}
}
QueenHeather Hancroft
Registered User
Join date: 26 Sep 2008
Posts: 20
10-15-2009 18:29
thanks,

if(llList2String(llParseString2List(msg,["|"],[""]),0) == "tenantshome" && rented)

this is exactly what i wanted,

reason being, incase i needed to use linked msgs for multiple strings. not just if "tenantshome"

its been fun, bedtime now.
no doubt ill be back tomorrow with bigger, better & new problems
zZz
LizardTongue Surface
Registered User
Join date: 31 May 2005
Posts: 11
mileage may vary
10-16-2009 20:16
The way I worked this in mine was to use the second parameter so my sending code is

CODE


integer ParseThis = TRUE;
llMessageLinked(LINK_THIS, ParseThis, MessageOut, NULL_KEY)

[\PHP]

Then my receiver has:

CODE

link_message(integer sender, integer ParseThis, string MessageIn, key id)
{ // open brace for link_message event

if (ParseThis)

{ // open brace for true path of if statement

list complexMessage = llParseString2List(MessageIn, ["|"], []);
command = complexMessage[0]; // assumes command is first item in list

} // close brace for true path of if statement

else command = MessageIn;

state myStateProcessCommands;

} // close brace for link_message event


Of course you can do whatever you want in place of the state change command there :)