Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

(1st try) Sensor and Listen problem

Jolan Nolan
wannabe
Join date: 12 Feb 2006
Posts: 243
08-29-2006 19:27
Ok. I have two sliding doors that I want to open when you step in front of them. I've tested the sensor and it works ok but my problem seems to be with the door. I seems like it will either listen once and begin an infinite loop, listen once and not do anything or perform both commands regardless of what it hears.
I may be missing some stuff because I want it to work as simple as possible.

Here is the sensor code, just in case
CODE

integer channel = 330; //Listen channel for the doors, should be the same for them.
float range = 3; //Distance in meters from the sensor

default
{
state_entry()
{
llSensor("", NULL_KEY, AGENT, range, PI_BY_TWO);
}
touch_start(integer touchies) //Click to make sensor cube invisible
{
llSetAlpha(0.0, ALL_SIDES); // set entire prim 100% invisible.
}
sensor(integer detectees)
{
llSay(channel,"door1_open");
llSleep(1);
llResetScript(); //include this or it will only check once
}
no_sensor()
{
llSay(channel,"door1_close");
llSleep(1);
llResetScript(); //include this or it will only check once
}


}


And here is the door.
CODE

vector open = <75.717,75.802,236>; //Set this to its open position "open = <x,y,z>"
vector closed = <75.717,74.900,236>; //Set this to its closed position "closed = <x,y,z>"
integer channel = 330; //The same channel used in the Sensor

default
{
state_entry()
{
llResetScript();
llListen(channel,"","","" );
}
listen(integer channel, string name, key id, string message)
{
if (message == "door1_open")
{
llSetPos(open);
llOwnerSay("Open");
state default;
}
else if(message == "door1_close")
{
llSetPos(closed);
llOwnerSay("Closed");
state default;
}
}
}


Feel free to edit any of the comments as they are all mine and some are probably wrong :P

- Jolan
ed44 Gupte
Explorer (Retired)
Join date: 7 Oct 2005
Posts: 638
08-29-2006 21:01
I would not use the llResetScript anywhere except in the on_rez call back. It is like restarting your script, state, variables and listeners so your listen will never be executed.

See the wiki:
http://secondlife.com/badgeo/wakka.php?wakka=llResetScript
HtF Visconti
Registered User
Join date: 21 Jul 2006
Posts: 123
08-30-2006 03:46
Well - I may be wrong but I just don't really understand your approach.

If you want to have a continuous scan why do you not just use llSensorRepeat? This scanning once, seeing if something happened or not and then resetting the script to scan again seems a bit .... strange. Unless there's a good reason for this I wouldn't use this approach.

In addition - placing the reset comman in the state_entry event is like closing a door whenever it opens and telling the door to open once it is closed .... you get a loop of startup and reset that will probably produce an undefined state.

Just remove the reset command from the state_entry event and thing should work fine.

Is there a reason you so persistently use llResetScript?
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
08-30-2006 04:47
Other pointed out things aside, continuous 3d scan in hope an avatar may occasionally happen to pass by ... it's not very healthy, especially once the number of such scripts start adding up ^^;

would suggest to place a prim covering the door area and sticking out a bit on both sides, and use it for llVolumeDetect() based events. You'll be then notified every time someone enters and leaves the area of this prim, which tells you when to open and close your door, respectively...

just sayin' o.o;
Jolan Nolan
wannabe
Join date: 12 Feb 2006
Posts: 243
08-30-2006 06:38
I used ResetScript because the sensor would only trigger once periode. I haven't tried SensorRepeat or Volume Detect because this is my first try at sensor anything and in QBasic and the Ti-83 calculator I just used loops. That was my first guess after it wasn't working. Last night at work I thought of maybe using states like a toggle switch... :confused:. I'll check those out, thanks.

*EDIT* Well wtf, that llVolumeDetect is exactly what I wanted :P.
It works perfectly now :D

- Jolan