Jump to content

Trouble making prim detect correct position


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

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

Recommended Posts

For some reason my prim detected the end position fine but then later on it doesn't work anymore. Here is my code:

 

integer on = TRUE;
vector pos;
vector startpos = <81.287,87.940,30.251>;
vector endpos = <81.787,84.690,30.451>;
key ToucherID;
integer channel_dialog;
integer listen_id;
list choice = ["1V", "3V", "5V"];
string msg = "Please choose a voltage value for battery:";

default
{
    state_entry()
    {
        llSetText("Touch to move voltage source",<0,1,0>,1);
        llListen(-20, "", "", "");
        channel_dialog = ( -1 *
(integer)("0x"+llGetSubString((string)llGetKey(),-5,-1)) );
    }

    listen(integer channel, string name, key id, string choice)
    {
        if(channel == -20)
        {
            llSetText("Reset!",<0,1,0>,1);
            llSetPos(startpos);
            llResetScript();
        }
        else if (choice == "1V")
        {
            llShout(30, "");
            llListenRemove(listen_id); //HERE WE ARE BEING RESPONSIBLE
        }
        else if (choice == "3V")
        {
            llShout(31, "");
            llListenRemove(listen_id); //HERE WE ARE BEING RESPONSIBLE
        }
        else if (choice == "5V")
        {
            llShout(32, "");
            llListenRemove(listen_id); //HERE WE ARE BEING RESPONSIBLE
        }
        else
        {
            llShout(33, "");
            llListenRemove(listen_id); //HERE WE ARE BEING RESPONSIBLE
        }
    }
   
    touch_start(integer x)
    {
        pos = llGetLocalPos();
       
        if (on == TRUE)
        {
           listen_id = llListen( channel_dialog, "", ToucherID, "");
           llSetPos(llGetLocalPos() + <0,0,0.2>);
           llRequestPermissions(llDetectedKey(0), PERMISSION_TAKE_CONTROLS);
           on = FALSE;
        }   
        else if(pos == endpos)
        {
            llSetText("Correct placement!",<0,1,0>,1);
            llSleep(3.0);
            llReleaseControls();
            llSetText(msg, <1,1,1>,1);
            llSleep(3.0);
            ToucherID = llDetectedKey(0);
        llDialog(ToucherID, msg, choice, channel_dialog);
        listen_id = llListen( channel_dialog, "", ToucherID, "");
        llSetTimerEvent(60); //HERE WE SET A TIME LIMIT
        }
        else if (on == FALSE)
        {
            llSetText("Wrong spot...",<0,1,0>,1);
            llSetPos(pos);
            llRequestPermissions(llDetectedKey(0), PERMISSION_TAKE_CONTROLS);
            llReleaseControls();
            on = FALSE;
        }
    }
   
    run_time_permissions(integer perm)
    {
        integer controls = CONTROL_FWD | CONTROL_BACK |
             CONTROL_ROT_LEFT | CONTROL_ROT_RIGHT;
        if(perm & PERMISSION_TAKE_CONTROLS)
        {
            llTakeControls(controls, TRUE, FALSE);
        }
    }
   
    control(key id, integer level, integer edge)
    {
        integer button = level;
        if(button & CONTROL_FWD)
        {
            llSetPos(llGetLocalPos()+<0,-0.25,0>);
        }
        if(button & CONTROL_BACK)
        {
            llSetPos(llGetLocalPos()+<0,0.25,0>);
        }
        if(button & CONTROL_ROT_LEFT)
        {
            llSetPos(llGetLocalPos()+<0.25,0,0>);
        }
        if(button & CONTROL_ROT_RIGHT)
        {
            llSetPos(llGetLocalPos()+<-0.25,0,0>);
        }
    }
   
    timer()
    { //TIME?S UP!
        llListenRemove(listen_id);
        //llWhisper(0, "Times up.");
        llSetTimerEvent(0.0); //Stop the timer from being called repeatedly
    }
}

Link to post
Share on other sites

It would help if you explained what you're trying to achieve so we didn't have to try to work it out from your code.  At least you pasted that so we can.

"else if(pos == endpos)" is VERY precise when "vector endpos = <81.787,84.690,30.451>;"

It has to be within a millimetre in all three dimensions.  Round and test within bounds rather than for a single value.

  • Like 1
Link to post
Share on other sites

Good to see you back again, s32.  I assume that this is part of the circuit board simulation project that you described the last time you posted here.  Peter's right.  Treat this like a real circuit board.  You get the component in roughly the right place and its pins will line up well enough to plug it in.  Just figure out how you're going to write

if (pos == close_enough_to_endpos)

and you've got it made.  Hint:   llVecDist .

  • Like 1
Link to post
Share on other sites

It's worse than that pete... it has to be EXACT... some rounding in the intial position or the region save state on a reset and it'll never hit. even if it's less than an an angstrom away from the target position.

if you want high precision and still some sane flexibility, llTarget and the at_target event

 

the other option is check if position is less than a certain value from your target position

Link to post
Share on other sites
You are about to reply to a thread that has been inactive for 3553 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
×
×
  • Create New...