Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

The object that refuses to die

Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
11-25-2008 18:15
New problem today. I've written a dialog-driven script that lets a user choose which one of several objects to rez at a given spot. The relevant part of the script that creates whatever object the user chooses looks like this ....

CODE

{
benchname = "Big Bench";
llSay(killchannel, (string)killoffset);

// killchannel is defined elsewhere as an integer = 3657 and killoffset = 10

llOwnerSay((string)killchannel + (string)killoffset);

// This debug statement yields the result 365710, as it should

llRezObject(benchname, llGetPos() + <2, 0, 0> + kvector, ZERO_VECTOR, ZERO_ROTATION, killoffset);
}


and the object to be rezzed has a script in it that looks like this ......

CODE

integer channel;
string tag;
default
{
on_rez(integer start_param)
{
tag = (string)start_param;
llSetObjectName(llGetObjectName() + tag);
llSay(0,"Hello! I am your new bench. Please take a seat.");

// The script works fine to this point. The object is created with name =Big Bench10.

}

state_entry()
{
channel = 3657 + (integer)tag;
llListen(channel,"",NULL_KEY,"");
}
listen(integer channel, string name, key id, string message)
{
string kill = llGetSubString(llGetObjectName(), -2, -1);
if(message == kill)
{
llDie();
}
}
}


If I only wanted to rez one object once, I would be happy. The script does that. If I run the script a second time, though, it SHOULD delete the object that I rezzed the first time. It doesn't. HOWEVER, if I type "/3667 10" in chat, the previously rezzed object dies beautifully. I really don't understand what's going on. Because it understands the command when I type it, the rezzed object obviously knows what channel to listen on, and it knows how to make the variable "kill" properly. So why won't it listen to the same command when the parent object says it on that channel?

EDIT: Hold on.... I may have found the mistake..... IF someone else sees what I do, don't hesitate to tell me.
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
11-25-2008 20:40
In one place you say "10" on channel 3657. In one place you "add" 3657 and 10 together as strings, concatenating to get "3657"+"10"="365710". In one place you add 3657 and 10 together as integers to get 3657+10=3667, which is the channel you are listening on. So you listen on channel 3667 and chat on channel 3657. Obviously that's not going to work.
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
11-25-2008 21:12
Yup.... I spotted that after I posted....... soft brain.:rolleyes:
SuezanneC Baskerville
Forums Rock!
Join date: 22 Dec 2003
Posts: 14,229
11-25-2008 21:35
At least it wasn't using = instead of ==.
_____________________
-

So long to these forums, the vBulletin forums that used to be at forums.secondlife.com. I will miss them.

I can be found on the web by searching for "SuezanneC Baskerville", or go to

http://www.google.com/profiles/suezanne

-

http://lindenlab.tribe.net/ created on 11/19/03.

Members: Ben, Catherine, Colin, Cory, Dan, Doug, Jim, Philip, Phoenix, Richard,
Robin, and Ryan

-
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
11-26-2008 06:41
Yeah..... I think it was Winston Churchill who once commented that the best measure of progress is not how many problems you have solved, but whether you are working on a different problem today than you were yesterday. I can easily come up with a new problem every day. ;) Thanks.
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
This is going to look like a dumb post, now that it's edited *rolling eyes*
11-26-2008 09:38
Arrgh! OK, I thought I had this one. Yes, I made a silly arithmetic error, and I cleaned it up. The script still wasn't running properly, though, so I trashed it and created a MUCH simpler script to put in the newly rezzed object. The new script looks like this ....

CODE

integer channel;
default
{
on_rez(integer start_param)
{
integer tag = llGetStartParameter();
llOwnerSay("start = " +(string)llGetStartParameter());
llOwnerSay("tag = " + (string)tag);
if (tag == 10)
{
llOwnerSay("Yes, tag = " +(string)tag);
channel = 3667;
llOwnerSay("Channel = " + (string)channel);
}
else if (tag == 20)
{
llOwnerSay("Yes, tag = " +(string)tag);
channel = 3677;
llOwnerSay("Channel = " + (string)channel);
}
else if (tag == 30)
{
llOwnerSay("Yes, tag = " +(string)tag);
channel = 3687;
llOwnerSay("Channel = " + (string)channel);
}
else
{channel == 0;}
llOwnerSay ("Channel = " + (string)channel);
}
state_entry()
{
llOwnerSay ("OK, I'm ready to listen on channel = " + (string)channel );
llListen(channel,"",NULL_KEY,"");
}
listen(integer channel, string name, key id, string message)
{
llOwnerSay(message);
if(message == "kill")
{
llDie();
}
}
}


I pass start_param = 10 with the llRezObject statement that creates the object. The debug statements I put in the on_rez event all fire correctly and they tell me that start_param and tag are both = 10, and that channel = 3667. I get absolutely NO output from the debug statement in state_entry, though, and the listen event doesn't trigger if I have the parent script say "kill" on channel 3667 or if I type "/3667 kill" in chat. It DOES trigger if I type "kill" in chat on channel 0.

Clearly, I am misunderstanding something here, but I am still new enough at LSL that I don't know what I don't understand.
(1)The variable "channel" is global, so it should be = 3667 in all states once I have defined it in on_rez, shouldn't it?
(2)The script should enter state_entry naturally and at least execute my debug statement, shouldn't it?
(3)I tried moving the block of statements that define "channel" from on_rez to state_entry and absolutely NOTHING happens, but shouldn't llGetStartParameter pick up the value of start_param no matter what state I call it from?
(4)What the heck am I doing wrong here? What am I missing?:confused:

NOTE ADDED IN FINAL EDIT!!!!!!! >>>>>>> Wow! I got it! I didn't realize that an script doesn't enter state_entry when the object containing it is rezzed. I got rid of state_entry and moved its contents to on_rez, and the script executes beautifully. Cleaned up, the whole thing is reduced to about 10 lines of code and is lovely.

Pardon me for carrying on this conversation with myself. I kept tinkering while I was waiting for expert guidance, and I actually learned something.

/me smiles and goes out for a cold beer.....:)