Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Handling Variables

Vaan Wellman
Registered User
Join date: 28 Jan 2007
Posts: 7
02-03-2007 07:05
Hey everyone. I just started scripting in LSL, and I was wondering how to change a variable within another object, or if its even possible. I know in another language I used, I could put a handler in it, like object.number, would change object's number variable. Any suggestions would be extremely helpful. Thanks in advance
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
02-03-2007 08:51
From: Vaan Wellman
Hey everyone. I just started scripting in LSL, and I was wondering how to change a variable within another object, or if its even possible. I know in another language I used, I could put a handler in it, like object.number, would change object's number variable. Any suggestions would be extremely helpful. Thanks in advance


What you have to take in to account that in most langauges where the above notation works you either create the object locally in the first place or obtain a pointer/reference to it via a standardised API call. SL just isnt that kind of a system!

It would be even more of a griefers paradise if anyone could request control of any object / prim in such a manner.

Depending upon exactly what sort of data you are trying to modify.
You can use so called 'hidden' faces on prims and set the colour or alpha which the second object would then read and use to perform some action. But that is only good for very small amounts of data.

Another method is for the objects to send each other notecards, but since you cannot modify a notecard this limits you to fixed values.

A more conventional method is for the objects to set up a common channel and communicate on that using llSay, llShout or llWhisper. For objects out of range of shouts there is llEmail.

What sort of thing are you trying to do?
Vaan Wellman
Registered User
Join date: 28 Jan 2007
Posts: 7
02-03-2007 13:17
Well what I'm trying to do is modify a health variable on an object when my object collides with it. I tried using llDetectedName.variable but it comes up with a syntax error. I'm a little confused about what you mean with the faces and prims, but your llSay idea sounds interesting. I'll try that later. Thanks for the quick reply.
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
02-03-2007 14:34
From: Vaan Wellman
Well what I'm trying to do is modify a health variable on an object when my object collides with it. I tried using llDetectedName.variable but it comes up with a syntax error. I'm a little confused about what you mean with the faces and prims, but your llSay idea sounds interesting. I'll try that later. Thanks for the quick reply.



The llDetectedname function takes an index parameter but as has been previously stated you cannot use that syntax in LSL.

What you are describing is basic HP stuff, try using a llWhispher on a specifc channel.
Below is a very primitive implementation, just to show the idea

CODE

integer channel = - 999999; // Channel we will all talk on.
string hits = "10"; // 10 pts of damage for this item
list hitid; // The items that have hit us
integer health = 100; // Our current health
string damage; // the string we will send to other objects

integer listening;

default
{
state_entry()
{
damage = (string)llGetKey() + "=" + hits; // Create our damage string
}

collision_start(integer total_number)
{
// Build a list of the items that hit us.
hitid = = [];
for(i =0 ; i < total_number; i++)
{
hitid += [ llDetectedKey(0) ];
}
llSetTimerEvent(5); // Allow 5 seconds for all items to report hits
listening = llListen(channel,"","",""); // Listen for hits
llWhisper(channel, damage); // Say our damage
}

listen(integer channel, string name, key id, string message)
{
list ldata = llParseString2List(message, ["="], [""]);
key attackid= llList2Key(ldata,0);
string value = llList2String(ldata,1);
integer index = llListFindList(hitid, attackid);
if(index >= 0)
{
health -= (integer)value;
if(health <= 0)llDie();
}
}

// cancel the listen after 5 seconds
timer()
{
llSetTimerEvent(0);
llListenRemove(listening);
listening = 0;
}
}
Vaan Wellman
Registered User
Join date: 28 Jan 2007
Posts: 7
02-03-2007 17:23
I've tried using your method just a while ago, and I got great results. Thanks for the example code, it was a great help for me.
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
02-03-2007 20:40
From: Vaan Wellman
I'm a little confused about what you mean with the faces and prims,


well, you don't plan to use it, so it doesn't really matter, but I'll explain...

A script can set and get the color or other parameters of the side of a prim, such as a box. So, you take a face that nobody can see, and you make up a protocol for passing information by changing the parameters of that face. for example, if a script thinks you are dead, it can make the bottom of your shoe RED. If some other script wants to know if you are dead, it checks the color of the bottom of your shoe.

I've never done this, but it might be possible to do something like this.