Jump to content

Modify script with on/off toggle with touch


vandaMJ Addens
 Share

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

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

Recommended Posts

I have a script that will make a set of wings move to flap by script coding, not animation. I am allowed to modify the script but my scripting knowledge is limited. I would like to modify (or use another script to control the other one) the script so anyone owning the wing could touch it to stop the flap and turn on and off when they want to stop the wings. Is this possible? If so can anyone help me with this? Thank you.

This is the script I have for my wings.

float counter;

integer stage = 0;

float wing_speed = 0.1;
float degrees_per_increment = 2;

default
{
    state_entry()
    {
        llSetLinkPrimitiveParamsFast(2,[PRIM_ROT_LOCAL,llEuler2Rot(<180.0,0.0,0>*DEG_TO_RAD),PRIM_LINK_TARGET,3,PRIM_ROT_LOCAL,llEuler2Rot(<0.0,0.0,0>*DEG_TO_RAD)]);
        llSetTimerEvent(wing_speed);
    }
    attach(key id)
    {
        if(id)
        {
            llResetScript();
        }
    }
    timer()
    {
        if(stage == 0)
        {
            counter += degrees_per_increment;
            if(counter >= 20)
            {
                stage = 1;
            }
        }
        else if(stage == 1)
        {
            counter -= degrees_per_increment;
            if(counter <= 0)
            {
                stage = 0;
            }
        }
        llSetLinkPrimitiveParamsFast(2,[PRIM_ROT_LOCAL,llEuler2Rot(<180.0,0.0,counter>*DEG_TO_RAD),PRIM_LINK_TARGET,3,PRIM_ROT_LOCAL,llEuler2Rot(<0.0,0.0,counter>*DEG_TO_RAD)]);
    }
}

Edited by vandaMJ Addens
Link to comment
Share on other sites

Here's a modified script that might do the job:

float counter;

integer stage = 0;

integer flapping; //not flapping/flapping flag (keeps track of whether the wings are flapping)

float wing_speed = 0.1;
float degrees_per_increment = 2;

default
{
    state_entry()
    {
        llSetLinkPrimitiveParamsFast(2,[PRIM_ROT_LOCAL,llEuler2Rot(<180.0,0.0,0>*DEG_TO_RAD),PRIM_LINK_TARGET,3,PRIM_ROT_LOCAL,llEuler2Rot(<0.0,0.0,0>*DEG_TO_RAD)]);
        //llSetTimerEvent(wing_speed); //don't start the timer until there's been a click
    }
    touch_start (integer count) //there's been a click
    {
        if (flapping) //are the wings flapping?
        {
            llSetTimerEvent (0.0); //stop the timer (where the flapping movements are done)
            flapping = FALSE; //reset the flag
            llSetLinkPrimitiveParamsFast(2,[PRIM_ROT_LOCAL,llEuler2Rot(<180.0,0.0,0>*DEG_TO_RAD),PRIM_LINK_TARGET,3,PRIM_ROT_LOCAL,llEuler2Rot(<0.0,0.0,0>*DEG_TO_RAD)]); //park the wings in their non-flapping position
            counter = 0.0; //reset the counter (wich keeps track of where in the flap the wings are)
        }
        else //no, the wings aren't flapping: 
        {
            llSetTimerEvent (wing_speed); //start the timer
            flapping = TRUE; //set the flag
        }
    }
    attach(key id)
    {
        if(id)
        {
            llResetScript();
        }
    }
    timer()
    {
        if(stage == 0)
        {
            counter += degrees_per_increment;
            if(counter >= 20)
            {
                stage = 1;
            }
        }
        else if(stage == 1)
        {
            counter -= degrees_per_increment;
            if(counter <= 0)
            {
                stage = 0;
            }
        }
        llSetLinkPrimitiveParamsFast(2,[PRIM_ROT_LOCAL,llEuler2Rot(<180.0,0.0,counter>*DEG_TO_RAD),PRIM_LINK_TARGET,3,PRIM_ROT_LOCAL,llEuler2Rot(<0.0,0.0,counter>*DEG_TO_RAD)]);
    }
}

 

Edited by KT Kingsley
Spelling
  • Thanks 1
Link to comment
Share on other sites

Thank you KT Kingsley

I appreciate the try, I was quite happy and I tried to use your code but the script didn't work because, I forgot to mention (and I am really sorry) that to make the wings move I have to put the script inside a transparent cube that I link to the wings and then the wings move due to the cube's link with them. Probably this is why it is not working. The only way I stopped the wings by clicking was when I bought a script that controls scripts but it's no modify and it has a lot of options that I don't need. I used it and it stopped the wing when I clicked but the menu is confusing for people who wants to use the wings. I'm thinking if I need another code or a controller script, but I don't know LSL scripting that much. Having a menu to turn on and off could be good too because I want to attach a script Color Hud to the wings too and create like a 'Professional' scripted hud for the Wings.  I'm doing this for 3 days and I'm about to give up Q_Q

Link to comment
Share on other sites

I did try that script in the root prim of three linked cubes and the child prims showed what seemed to be the correct flapping behaviour with the flapping turned on and off by clicking any of the prims.

This should work if you have your transparent root prim containing the script and the two wings linked to it as child prims. When you link objects it's the last object selected that becomes the root, so select the two wings first and then the transparent one, in that order, before linking them.

Linking other items will upset the script because doing so messes with the link numbers, and it's link numbers 2 and 3 that it assumes are the wings. (Also, the order in which you select the wings for linking will determine their link numbers and hence the direction in which they move when flapping.)

  • Thanks 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 551 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...