Jump to content

Restart state without affecting anything else in the script, possible? (HALP!)


Seren Tiratzo
 Share

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

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

Recommended Posts

So I have this script where I want one part to change textures on the root prim and change the shape of the child prim.
I can't figure out how to reset the child prim's state without restarting the root prim's state as well.

list textures = [
    "d7db2561-a605-021b-cdc3-ddc45f880960",
    "8f0ef10d-c48c-d92c-98bb-8dd8bc7349f4",
    "1f2878f2-abff-67ea-5d9b-0c97e227cbe9"];
 

list sides = [
    "0,1,2,5",
    "1,3,4,1"];
float frequency = 2.0;
 

integer random = TRUE;
integer duplicatecheck = TRUE;
 
 

 
changetexture()//user fucntion to change texture
{
    integer counter;
    key texture = llList2String(textures,currenttexture);//gets texture key from list
    do
    {
        //also with another script
        list primdata = llCSV2List(llList2String(sides,counter));
        integer prim = llList2Integer(primdata,0);
        integer primlistlength = llGetListLength(primdata);
        integer primlistcounter = 1;//start at 1 since the prim datalist's 1st entry is the prim
        do
        {
            
            llSetLinkTexture(prim,texture,llList2Integer(sides,primlistcounter));
        }while(++primlistcounter < primlistlength);
    }while(++counter <numberofsidestochange);
}
 
default
{
    on_rez(integer start_param)//on rez reset...probably not needed.
    {
        llResetScript();
    }
    state_entry()
    {
        llOwnerSay("Simple Texture Changer (input list)(multiple prims & multiple sides)");
        numberoftextures = llGetListLength(textures);
        numberofsidestochange = llGetListLength(sides);
        //assume correct
        llOwnerSay("There are " + (string)numberoftextures + " pictures which I will change every "
            + (string)frequency + " seconds.");
        llOwnerSay("My current free memory is : " + (string)llGetFreeMemory()
            + " bytes. If it is below 2500 bytes, I may not work properly.");
        llSetLinkPrimitiveParams(2,[PRIM_TYPE, PRIM_TYPE_SPHERE, 0, <0.150,0.900,0.00>, 0.0, <0,0,0>, <0,1,0>]);
        llSetTimerEvent(frequency);
    }
    timer()
    {
        state blink;
        if(random)//show pics randomly
        {
            integer randomtexture;
            if(duplicatecheck)//whether to make sure random doesn't repeat itself
            {
                do
                {
                    randomtexture= llRound(llFrand(numberoftextures - 1));//generate random number
                }while(randomtexture == currenttexture);//make sure the random one isn't the same as the current one
            }
            else//no duplicate check
                randomtexture = llRound(llFrand(numberoftextures - 1));//generate random texture number
            currenttexture = randomtexture;//set the current one to the random one selected
            changetexture();//change the texture
        }
        else//not random, go in order
        {
            ++currenttexture;
            if(currenttexture == numberoftextures)//if current texture = number of textures, reset counter
                currenttexture = 0;
            changetexture();//change the texture
        }
    }
    
}
state blink
{
    state_entry()
    {
        llSetLinkPrimitiveParams(2,[PRIM_TYPE, PRIM_TYPE_SPHERE, 0, <0.100,0.950,0.00>, 0.0, <0,0,0>, <0,1,0>]);
        llSetLinkPrimitiveParams(2,[PRIM_TYPE, PRIM_TYPE_SPHERE, 0, <0.0  ,1.00, 0.00>, 0.0, <0,0,0>, <0,1,0>]);
        llSetLinkPrimitiveParams(2,[PRIM_TYPE, PRIM_TYPE_SPHERE, 0, <0.100,0.950,0.00>, 0.0, <0,0,0>, <0,1,0>]);
        //how do I reset the current state without affecting anything else in the script
    }
}

 

Link to comment
Share on other sites

It's not quite clear to me what you are asking, but I'll take a crack at it.  You have a linkset with two prims, one of which is supposed to change shape periodically and the other of which (the root) is supposed to switch textures.  You want to be able to do those two operations independently, right?  If so, you need two timers.  You can do that in either of two common ways:

1. Use a single timer event that runs a heartbeat, and let each of your operations act on a different multiple of heartbeats.  So you change texures on the root prim every third heartbeat but change shape on the child prim on every beat. That's multiplexing.

timer(){    ++gCount;  // gCount is a global integer    //Change shape    if (gCount%3 == 0)    {        //Change texture    }}

 2.  Use a standard timer for one operation (say, shape change) and fake a second timer to handle the other one:

llSensorRepeat("Uncle Bob Przbulski","",AGENT,0.1,PI,3.0);no_sensor(){    //Darn, didn't find Uncle Bob, but go ahead and change texture anyway}

You don't need to put the three "blink" function calls in a new state blink at all.

One nice thing about the second option is that you can change the frequency of the timer event on the fly if you want to -- even trigger it at random times -- without affecting the fake timer.

All of this is irrelevant if I have totally misinterpreted your question.

BTW, your randomtexture function should be simply

    randomtexture = (integer)llFrand(numberoftextures);

The range of results of llFrand will be [0,numberoftextures - 1], and typecasting is more efficient than calling llRound.

 

 

 

Link to comment
Share on other sites

Thankyou for your quick reply but I think you misunderstood my question. I want both states to run on the same timer but one keeps looping and the other just runs.

Now take note that I didn't write these scripts from scratch, I'm trying to combine them.

I have one sphere that changes textures and another sphere thats around the first one that opens and closes.

Sphere 1. (change textures)

 

list textures = [    "d7db2561-a605-021b-cdc3-ddc45f880960",    "8f0ef10d-c48c-d92c-98bb-8dd8bc7349f4",    "1f2878f2-abff-67ea-5d9b-0c97e227cbe9"]; list sides = [    "0,1,2,5",    "1,3,4,1"];float frequency = 2.0; integer random = TRUE;integer duplicatecheck = TRUE;   changetexture()//user fucntion to change texture{    integer counter;    key texture = llList2String(textures,currenttexture);//gets texture key from list    do    {        //also with another script        list primdata = llCSV2List(llList2String(sides,counter));        integer prim = llList2Integer(primdata,0);        integer primlistlength = llGetListLength(primdata);        integer primlistcounter = 1;//start at 1 since the prim datalist's 1st entry is the prim        do        {                        llSetLinkTexture(prim,texture,llList2Integer(sides,primlistcounter));        }while(++primlistcounter < primlistlength);    }while(++counter <numberofsidestochange);} default{    on_rez(integer start_param)//on rez reset...probably not needed.    {        llResetScript();    }    state_entry()    {        llOwnerSay("Simple Texture Changer (input list)(multiple prims & multiple sides)");        numberoftextures = llGetListLength(textures);        numberofsidestochange = llGetListLength(sides);        //assume correct        llOwnerSay("There are " + (string)numberoftextures + " pictures which I will change every "            + (string)frequency + " seconds.");        llOwnerSay("My current free memory is : " + (string)llGetFreeMemory()            + " bytes. If it is below 2500 bytes, I may not work properly.");        llSetLinkPrimitiveParams(2,[PRIM_TYPE, PRIM_TYPE_SPHERE, 0, <0.150,0.900,0.00>, 0.0, <0,0,0>, <0,1,0>]);        llSetTimerEvent(frequency);    }    timer()    {        state blink;        if(random)//show pics randomly        {            integer randomtexture;            if(duplicatecheck)//whether to make sure random doesn't repeat itself            {                do                {                    randomtexture= llRound(llFrand(numberoftextures - 1));//generate random number                }while(randomtexture == currenttexture);//make sure the random one isn't the same as the current one            }            else//no duplicate check                randomtexture = llRound(llFrand(numberoftextures - 1));//generate random texture number            currenttexture = randomtexture;//set the current one to the random one selected            changetexture();//change the texture        }        else//not random, go in order        {            ++currenttexture;            if(currenttexture == numberoftextures)//if current texture = number of textures, reset counter                currenttexture = 0;            changetexture();//change the texture        }    }    }

Sphere 2. (close/open-loop)

state blink{    state_entry()    {        llSetLinkPrimitiveParams(2,[PRIM_TYPE, PRIM_TYPE_SPHERE, 0, <0.100,0.950,0.00>, 0.0, <0,0,0>, <0,1,0>]);        llSetLinkPrimitiveParams(2,[PRIM_TYPE, PRIM_TYPE_SPHERE, 0, <0.0  ,1.00, 0.00>, 0.0, <0,0,0>, <0,1,0>]);        llSetLinkPrimitiveParams(2,[PRIM_TYPE, PRIM_TYPE_SPHERE, 0, <0.100,0.950,0.00>, 0.0, <0,0,0>, <0,1,0>]);        //how do I reset the current state without affecting anything else in the script    }}

 But I can't figure out for the life of me how to loop the state that affects the childprim without affecting the texture change

Link to comment
Share on other sites

pretty much [kinda] yes in your case

a timer in both execute and blink states

when the execute timer (set in execute start_entry) fires execute the texture changes then call state blink. When the blink timer (set in blink start entry) t fires then run the blink and then call state execute

+

eta: kinda

+

edit more as a fyi

can daisy chain this method to have multiple states with multiple timers

Link to comment
Share on other sites

It amounts to exactly the same thing.  When the actions in your state bling "just run", they are executing a VERY rapid loop over and over again, each time you enter that state.You are running two processes repeatedly.  Hence, two timers.  You can put the timers in separate states, as a couple of people have suggested, or you can run them from a single state, either by multiplexing or running one of the processes with a fake timer.

Link to comment
Share on other sites

I don't see the need for states and Rolig explained everything about 2 timers.

If you want to do 2 things at the same time - states will not help you since only one state is active at a time. I have the impression that you aren't aware of that.

For 2 simultaneously running timers you can use a multiplexed timer or 2 timers (sensor trick) or 2 scripts but not 2 states.

For 2 timers runnung after each other you can use different states, but is not necessary.

 

I noticed that you have a 2 sec timer and every llSetLinkTexture and llSetLinkPrimitiveParams has a delay of 0.2 seconds. So it's possible that the execution one one loop takes longer than 2 seconds and that will result in troubles. I don't know how many texture changes the double loop in changetexture() will use.

Another thing: if you enter a state the state_entry() event is executed. So every time you return to state default - if you want to return - the state_entry() event will run. If that is supposed to happen every 2 seconds you don't want to have the llOwnerSays there.

Link to comment
Share on other sites

yes. More than 1 state wont help the OP script any more than a single state multiplex timer will

+

for any readers then I try to explain

when have a single timer (multiplexed or not) in a single state then the timed tasks execute dependently (synchronised)

when have single timers (multiplexed or not) in multiple states then the timed tasks execute dependently (synchronised)

using the llSensorRepeat as well gives us two timers executing independently (unsynchronised) in the same state

+

so if was me then given the tasks the OP script has to perform in this case then go with a multiplex timer in a single state (like Rolig suggested earlier)

+

my post was more a design thing to answer the other part of OPs question. How to manage state changes so to not interfere with the script initialisation

Link to comment
Share on other sites

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