Jump to content
Sign in to follow this  
Wandering Soulstar

Sensor Script Not working - Help

Recommended Posts

I set up the following code to determine if the 'owners' were at home, if not a message would go out so that doors left open could close, lights get turned off, etc. But it seems not to be working, at least today. Anyone see anything wrong with it?

 

default
{
	state_entry()
	{
		//Start Sensor
		llSensorRepeat("", NULL_KEY, AGENT, 90, PI, 300.0);
		
	}//End state_entry

	sensor(integer total_number)
	{
		integer i = 0;
		integer found = FALSE;
		gOwnerStatus = ABSENT;

		while (found == FALSE && i < total_number)
		{
			string name = llDetectedName(i);
			if (name == RES_1 || name == RES_2)
			{
				found = TRUE;
				gOwnerStatus = AT_HOME;
			}
			i++;
		}
		llShout(USER_SENSOR_CH, gOwnerStatus);
	}

}//End Default

 

Share this post


Link to post
Share on other sites

Has it ever worked?

I have noticed that sometimes I've needed to put each test in the while statement in brackets, so

while (found == FALSE && i < total_number)

 becomes

while ( ( found == FALSE ) && ( i < total_number )  )

 

Share this post


Link to post
Share on other sites

In the code you posted, I can't really see a reason why it shouldn't work. The double brackets are good style, but are not required.

What exactly does not work?

Share this post


Link to post
Share on other sites

Assuming that your variables USER_SENSOR_CH,  RES_1 and RES_2 are global and have been given values, it ought to work.  However, you probably want to have a companion no_sensor event that sets gOwnerStatus = ABSENT and sends that message to your listening scripts.  After all, the sensor event will only be triggered if the script detects someone.  If there's nobody there to detect, your script won't send any message at all.  You also might want to consider using llRegionSay or llRegionSayTo instead of llShout, but that's a nuance that shouldn't affect how this part of the script behaves. 

Share this post


Link to post
Share on other sites

Thanks Rolig! It exactly was the omission of the no_sensor event that was the problem, I had forgotten that sensor only triggered if it actually sensed someone, and therefore my problem. All fixed!!!!

 

Thanks to all for reading and suggesting!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...