Jump to content

Key Control Breaks when adding msg==


woogalie
 Share

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

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

Recommended Posts

Hello helpful people!

I am back at it on the boat script, trying to add two commands that can be triggered with msg. I need the sheet angles to adjust when I type f or b and I have accomplished this by using the following code in the listen section of the script.

Quote

else if (msg=="f") sheetAngle+=1;
else if (msg=="b") sheetAngle-=1;

But when I add these to the listen section, the CONTROL_FWD and CONTROL_BACK keyboard controls that are further down the script stop working. A few lines down are "spin+" and "spin-" commands and they work just fine in conjunction with CONTROL_UP and CONTROL_DOWN which is boggling me. Take a look below.

Quote

                    //My Sheet Control Code
                    else if (msg=="f") sheetAngle+=1;
                    else if (msg=="b") sheetAngle-=1;
                    
                    // SPINNAKER HOIST/DROP
                    else if (msg=="spin" && SPIN_UP) DropSpin();
                    else if (msg=="spin" && !SPIN_UP) HoistSpin();

                    //SPINNAKER TRIM
                    else if (msg=="spin+") TrimSpinPlus();
                    else if (msg=="spin-") TrimSpinMinus();
 

So Below I am going to quote the control part of the script, the part that decides how up arrow & down arrow control the sheet angle as well ass page down and page up for spinnaker trim. NOTE the spinnaker section at the bottom is SOOOOO basic and it is working with the verbal commands also. The sheet trim just will not work as both up/down arrow AND verbal.

Quote

//sail/throttle controls - UP AND DOWN KEYS
        if ( held & change & CONTROL_FWD );
               
     {
         if (motor  && throttle < 3) throttle+=1;
 
   gTiming1 = TRUE;
   gTiming2 = TRUE;
   gTiming3 = TRUE;
   gTiming4 = TRUE;
    llResetTime();
}

if (held & ~change & CONTROL_FWD)
{
  if(gTiming1 && llGetTime()>0.0)           { sheetAngle+=1; gTiming1 = FALSE; }
   else if (gTiming2 && llGetTime() > .5 )  { sheetAngle+=4; gTiming2 = FALSE; }
   else if (gTiming3 && llGetTime() > 1.0) { sheetAngle+=5; gTiming3 = FALSE; }
   else if (gTiming4 && llGetTime() > 1.5) { sheetAngle+=30; gTiming4 = FALSE; } 
   if (sheetAngle>90) sheetAngle=90;

//Back arrow pushed
if ( held & change & CONTROL_BACK );
{
     if (motor  && throttle > -2) throttle-=1;
    gTiming1 = TRUE;
   gTiming2 = TRUE;
   gTiming3 = TRUE;
   gTiming4 = TRUE;
    llResetTime();
}

if (held & ~change & CONTROL_BACK)
{

      if(gTiming1 && llGetTime()>0.0)           { sheetAngle-=1; gTiming1 = FALSE; }
   else if (gTiming2 && llGetTime() > .5 )  { sheetAngle-=4; gTiming2 = FALSE; }
   else if (gTiming3 && llGetTime() > 1.0) { sheetAngle-=5; gTiming3 = FALSE; }
   else if (gTiming4 && llGetTime() > 1.5) { sheetAngle-=30; gTiming4 = FALSE; } 
   if (sheetAngle>90) sheetAngle=90;
}

 // down key touched - end

         //PGUP/PGDN Spinnaker control
        else if (change & held & CONTROL_UP) {
            TrimSpinPlus();
            
        }
        else if (change & held & CONTROL_DOWN) {
            TrimSpinMinus();
        }
    
    }    

Can anyone identify why the Spinnaker pageup/pagedown keys AND the msg spin+ or spin- are both working, but not the msg f and b for the sheet control?

Or perhaps a workaround for it?

Thanks to all who read and help solve this problem of mine. 

Link to comment
Share on other sites

SOLVED - Always after I post... lol

Ok so here is the code for the control section and you can see the change I made on the bottom to get both key control AND msg control. (This is so that I can use a HUD to also adjust sheet angles) 

Quote

 //Following section maps keyboard keys for boat control... I would NOT edit this section...

 
    control(key id, integer held, integer change) {
        //turning controls - LEFT AND RIGHT KEYS
        wTack=0;
        
        if ( (change & held & CONTROL_LEFT) || (held & CONTROL_LEFT) || (change & held & CONTROL_ROT_LEFT) || (held & CONTROL_ROT_LEFT) ) {
            if (sailing) llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION,<rotSpeed/2.0,0.0,rotSpeed>);
            else llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION,<-rotSpeed,0.0,rotSpeed/1.5>); // left key hold - end
        }
        else if ( (change & held & CONTROL_RIGHT) || (held & CONTROL_RIGHT) || (change & held & CONTROL_ROT_RIGHT) || (held & CONTROL_ROT_RIGHT) ) {
            if (sailing) llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION,<-rotSpeed/2.0,0.0,-rotSpeed>);
            else llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION,<rotSpeed,0.0,-rotSpeed/1.5>); // right key hold - end
        }
        else if ( (change & ~held & CONTROL_LEFT) || (change & ~held & CONTROL_ROT_LEFT) ) {
            llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION,<0.0,0.0,0.0>); // left key touched - end
        }
        else if ( (change & ~held & CONTROL_RIGHT) || (change & ~held & CONTROL_ROT_RIGHT) ) {
            llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION,<0.0,0.0,0.0>); // right key touched - end
        }
        //sail/throttle controls - UP AND DOWN KEYS
        if ( held & change & CONTROL_FWD );
               
     {
         if (motor  && throttle < 3) throttle+=1;
 
   gTiming1 = TRUE;
   gTiming2 = TRUE;
   gTiming3 = TRUE;
   gTiming4 = TRUE;
    llResetTime();
}

if (held & ~change & CONTROL_FWD)
{
  if(gTiming1 && llGetTime()>0.0)           { sheetAngle+=1; gTiming1 = FALSE; }
   else if (gTiming2 && llGetTime() > .5 )  { sheetAngle+=4; gTiming2 = FALSE; }
   else if (gTiming3 && llGetTime() > 1.0) { sheetAngle+=5; gTiming3 = FALSE; }
   else if (gTiming4 && llGetTime() > 1.5) { sheetAngle+=30; gTiming4 = FALSE; } 
   if (sheetAngle>90) sheetAngle=90;

//Back arrow pushed
if ( held & change & CONTROL_BACK );
{
     if (motor  && throttle > -2) throttle-=1;
    gTiming1 = TRUE;
   gTiming2 = TRUE;
   gTiming3 = TRUE;
   gTiming4 = TRUE;
    llResetTime();
}

if (held & ~change & CONTROL_BACK)
{

      if(gTiming1 && llGetTime()>0.0)           { sheetAngle-=1; gTiming1 = FALSE; }
   else if (gTiming2 && llGetTime() > .5 )  { sheetAngle-=4; gTiming2 = FALSE; }
   else if (gTiming3 && llGetTime() > 1.0) { sheetAngle-=5; gTiming3 = FALSE; }
   else if (gTiming4 && llGetTime() > 1.5) { sheetAngle-=30; gTiming4 = FALSE; } 
   if (sheetAngle>90) sheetAngle=90;
}

 // down key touched - end

         //PGUP/PGDN Spinnaker control
        else if (change & held & CONTROL_UP) {
            TrimSpinPlus();
            
        }
        else if (change & held & CONTROL_DOWN) {
            TrimSpinMinus();
        }

// Here is what I added to solve the problem and gain control again with msg control as well.
         else if (change & held & CONTROL_FWD) {
            sheetAngle+=1;
            
        }
        else if (change & held & CONTROL_BACK) {
            sheetAngle-=1;
        }
    
    }    
    
    // ------------------------------------- END GLOBAL BOAT CONTROLS ---
    

I sure hope my nonsense but also problem solving helps other boat makers in the future. 

Best, Woogalie.

Link to comment
Share on other sites

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

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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...