Jump to content

Solved: Stuck on llSensorRepeat


WendyTalia
 Share

You are about to reply to a thread that has been inactive for 1097 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

key AvKey; 
startsensor()
    {
    llSensorRepeat("", AvKey, AGENT, 20.0, PI, 10.0);
    llSetTimerEvent(90);
    }
default
{   
    touch_start(integer total_number)
    {
        AvKey = llDetectedKey(0); startsensor();
    }
    sensor(integer num_det)
    {    
        integer i;        for(i = 0; i < num_det; i++)       
        {  
               if (AvKey == llDetectedKey(i))
                    {
                        llSay(0, llGetUsername(AvKey) + " Detected");
                    }
               else {llShout(0, "Not Detected");   //this bit not working 
                    } 
        }
    }
    timer()
    {   
        llSensorRepeat("", AvKey, AGENT, 10.0, PI, 0.0);
    }    
}

 

I can't get the "else" bit to work for some reason. It's for a game where I don't want people cheating by going close to the object. It's just as important to know when they aren't in range.

Edited by WendyTalia
solved
Link to comment
Share on other sites

The sensor event will ONLY happen if an avatar is detected. The no_sensor event will happen if no avatar is in range. 

Edit: Never mind, I skimmed too fast.

Edit 2: Never mind, I think what I said still applies.

If the object is touched but NO ONE is near it, the sensor event won't trigger and you can't get it to shout. Your code works as long as someone else is near the object, but you will also need a no_sensor event with the same code as in the "else" condition.

Edited by Wulfie Reanimator
Link to comment
Share on other sites

A very good example of the no_sensor event can be found on the wiki.

http://wiki.secondlife.com/wiki/No_sensor

I'm assuming you're trying to see if the person who touched the prim is within 20m of the prim. Another way you could go about this like the example below. This may remove your use for the sensor. (Unless you want it, then don't do this.)

key avKey;
float distance = 20;

integer InRange(key uuid, float distance) {
    list data = llGetObjectDetails(uuid, [OBJECT_POS]);
    if(data == [])
        return 0;
    return llVecDist(llList2Vector(data, 0), llGetPos()) <= distance;
}

default {
    touch_start(integer n) {
        avKey = llDetectedKey(0);
        if(InRange(avKey, distance)) {
            llOwnerSay("Within Range");
        } else {
            llOwnerSay("Not within range");
        }
    }
}

 

  • Like 2
Link to comment
Share on other sites

As Innula and Shymus pointed out, there's no reason to need a sensor in this script.  That's just extra work. Your touch_start event automatically gives you llDetectedPos() information already if you ask for it.

BTW, For your own peace of mind in later scripts, and for anyone else who might be reading your scripts, I suggest never putting more than one statement on the same line of code.  When you're debugging code, it's easy to overlook an important instruction in lines like

2 hours ago, WendyTalia said:

    integer i;        for(i = 0; i < num_det; i++)

and

2 hours ago, WendyTalia said:

    AvKey = llDetectedKey(0); startsensor();

?

  • Like 2
Link to comment
Share on other sites

Thank you for your replies! That was a cleaned up version for the forum. Ha! I do need to work on formatting them.

The sensor is for an archery target so the on touch is just when you start the game. Then it needs to know if you stay at a reasonable distance. It's only for a short time then turns off when the game is finished so I figured that wouldn't be so bad. I added an owner option to turn the sensor off explaining it's not great for laggy sims. Do you think? 

Those scripts you posted are great ideas that could come in handy for other projects.Very simple. I love those adventure games with experiences where range on touch is essential. I have a few ides in mind. 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1097 days.

Please take a moment to consider if this thread is worth bumping.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...