hidden Loon Posted January 28, 2021 Share Posted January 28, 2021 I am making a staff and I want certain parts of it to move up and down. I am probably going about this the long way, but right now I have a script that says a command and it makes the child prim move. However, I was wanting to know how to make it loop the text string? This is what I have now: integer LISTENER_CHANNEL = 0; string ON_COMMAND = "vis"; string OFF_COMMAND = "invis"; integer OWNER_ONLY = TRUE; key my_owner = NULL_KEY; default { on_rez(integer n) { llResetScript(); } state_entry() { if ( OWNER_ONLY ) my_owner = llGetOwner(); llListen( LISTENER_CHANNEL, "", "", "" ); } listen( integer chan, string name, key target_id, string mesg ) { if ( OWNER_ONLY ) { if ( target_id != my_owner // Check the identity of the speaker && llGetOwnerKey(target_id) != my_owner ) { // check ID of the speaking prim's owner return; // skip the rest of this listen() block. } } if ( mesg == "vis" ) { llSay(0, "step"); //start moving llSleep(0.0001); //I want it to seem seemless but not instant movement llSay(0, "step"); ******** //maybe loop right here back to the start of the movement } else if ( mesg == "invis" ) { llResetScript(); //make it stop looping? } } } Below is the script for the child prim to move: turn() { llSetText("turn", <1,1,1>, 1); rotation smallAngle = llEuler2Rot(<0,0,15>*DEG_TO_RAD); rotation newRot = smallAngle*llGetLocalRot(); llSetLocalRot(newRot); } step() { llSetText("step", <1,1,1>, 1); vector forward = <0.1,0,0>; // short step on X vector toMove = forward*llGetLocalRot(); // point as I point vector newPos = llGetLocalPos()+toMove; llSetPos(newPos); } process(string message) { if ( message == "turn") { turn(); } else if ( message == "step" ) { step(); } else { llWhisper(0, "impossible"); } } default { state_entry() { llListen(0, "", "", "turn"); llListen(0, "", "", "step"); } listen(integer channel, string name, key id, string message) { process(message); } } Any help would be appreciated. Thanks! Link to comment Share on other sites More sharing options...
Mollymews Posted January 28, 2021 Share Posted January 28, 2021 am not sure what you mean by loop the text string if what you mean is to reset the prim(s) to their initial positions and rotations when mesg == "invis" then a way is to store the initial values as global constants and then on "invis" set the prim(s) position and rotation to the stored values Link to comment Share on other sites More sharing options...
hidden Loon Posted January 29, 2021 Author Share Posted January 29, 2021 15 hours ago, Mollymews said: am not sure what you mean by loop the text string if what you mean is to reset the prim(s) to their initial positions and rotations when mesg == "invis" then a way is to store the initial values as global constants and then on "invis" set the prim(s) position and rotation to the stored values Basically if it says llSay(0, "step1"); //start moving llSleep(0.0001); llSay(0, "step2"); llSleep(0.0001); llSay(0, "step3"); llSleep(0.0001); llSay(0, "step4"); I want it to loop back to "step1" and say the rest of the lines ( 2, 3, 4 etc) and then repeat back to 1 until I say a command to make it stop Link to comment Share on other sites More sharing options...
hidden Loon Posted January 29, 2021 Author Share Posted January 29, 2021 bump Link to comment Share on other sites More sharing options...
Mollymews Posted January 29, 2021 Share Posted January 29, 2021 (edited) 9 hours ago, hidden Loon said: Basically if it says llSay(0, "step1"); //start moving llSleep(0.0001); llSay(0, "step2"); llSleep(0.0001); llSay(0, "step3"); llSleep(0.0001); llSay(0, "step4"); I want it to loop back to "step1" and say the rest of the lines ( 2, 3, 4 etc) and then repeat back to 1 until I say a command to make it stop is lots of ways to do this. One way is to put the "step" commands into a list and then say them sequentially using a timer. Example // global vars list commands = ["step1", "step2", "step3", "step4"]; float COMMAND_WAIT_TIME = 1.0; // time to wait between each command integer command_index; integer number_of_commands; if (mesg == "vis") { number_of_commands = llListLength(commands); command_index = 0; llSay(0, llList2String(commands, command_index)); // say the 1st command llStartTimerEvent(COMMAND_WAIT_TIME); } else if (mesg == "invis") { llStopTimerEvent(0.0); // stop the timer. stop saying commands } timer() { // get and say the next command. rolling over to begin again at 0 when commands list exhausted command_index = (++command_index % number_of_commands); llSay(0, llList2String(commands, command_index)); } edit: some typos in the pcode above. Am sure you be able to work them out tho edit more: probably not a good idea to llSay on channel 0 (the public chat channel). Pick another channel to say on, as you don't want to spam the public chat if it can be helped Edited January 29, 2021 by Mollymews Link to comment Share on other sites More sharing options...
Recommended Posts
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