Xander Lopez Posted January 4, 2020 Share Posted January 4, 2020 I am trying to see how I can ensure that the first function is completed before running the function written in the next line. I have the following code shown as below: myFunction1() { llOwnerSay("do some crazy calculations here"); } myFunction2() { llOwnerSay("change some textures here"); } myFunction3() { llOwnerSay("change prim shape here"); } startMe1() { myFunction1(); myFunction2(); myFunction3(); } startMe2() { myFunction3(); myFunction2(); myFunction1(); } My assumption was that when startMe1() was executed, it would process myFunction1 first, and then process to myFunction2 only if myFunction2 is complete, and same thing goes for myFuction3. However, it appears to be that myFunction1(), myFunction2(), myFunction3() would execute one after another regardless of previous function was complete or not. I guess I could have written the code as below so they run after one another. myFunction1() { llOwnerSay("do some crazy calculations here"); myFunction2(); } myFunction2() { llOwnerSay("change some textures here"); myFunction3(); } myFunction3() { llOwnerSay("change prim shape here"); } myFunction1(); But the problem with this code is that now, i can't reuse this code in reverse way like I would love to run them in shown as startMe2() { myFunction3(); myFunction2(); myFunction1(); } Can anyone help me how I can manage these functions and ensure the first function is complete before next function runs? Link to comment Share on other sites More sharing options...
Ardy Lay Posted January 4, 2020 Share Posted January 4, 2020 (edited) I have run into situations where a script modifying an object appeared to be executing out of sequence but close inspection indicated that what was out of sequence was the updates to the viewer rendering the object. In my application it was irrelevant so I just ignored it and moved on. For my "close inspection" I used additional function calls in the script to read back the parameter changes that previous functions were applying and comparing the results. In the end, I decided to use the newer functions for modifying objects. They accept lists of parameters and resulted in much shorter scripts and faster completion of tasks. The also resulted in object updates being combined somewhat. This probably generated less work for the simulator, the viewer, and, perhaps, less network traffic. Edited January 4, 2020 by Ardy Lay Link to comment Share on other sites More sharing options...
Wulfie Reanimator Posted January 4, 2020 Share Posted January 4, 2020 I'm not quite sure I understand what the issue is. In LSL, events and functions are executed completely and sequentially. Given the code: start_me() { function1(); function2(); function3(); } function1() { llOwnerSay("function1"); } function2() { llOwnerSay("function2"); } function3() { llOwnerSay("function3"); } default { state_entry() { start_me(); llOwnerSay("done"); } } function3 will never begin before function2 has finished, which will never begin before function1 has finished. "done" won't show up before start_me has finished. 11 minutes ago, Xander Lopez said: However, it appears to be that myFunction1(), myFunction2(), myFunction3() would execute one after another regardless of previous function was complete or not. This is the most confusing part. What do you mean by "whether previous function was completed or not?" Do you use return values in your functions that would indicate an error, when the function returned early? You would need some if-checks for those return values before calling the next one. Link to comment Share on other sites More sharing options...
Xander Lopez Posted January 4, 2020 Author Share Posted January 4, 2020 @Wulfie Reanimator Let me make sure that what you said also applies to the following scenario. Would "function2()" run ONLY after function1() is complete when StartMe() is executed? function1() { //contains 600 lines of code doing complex calculations and send out 5 different llRegionSayTo() and then finally set a global integer myValue = 100;} function2() { //simply read the global integer myValue and change some prim color } function3() { //contains another 300 lines of code doing complex calculations } StartMe() { function1(); function2(); function3(); } Link to comment Share on other sites More sharing options...
Wulfie Reanimator Posted January 4, 2020 Share Posted January 4, 2020 1 minute ago, Xander Lopez said: @Wulfie Reanimator Let me make sure that what you said also applies to the following scenario. Would "function2()" run ONLY after function1() is complete when StartMe() is executed? function1() { //contains 600 lines of code doing complex calculations and send out 5 different llRegionSayTo() and then finally set a global integer myValue = 100;} function2() { //simply read the global integer myValue and change some prim color } function3() { //contains another 300 lines of code doing complex calculations } StartMe() { function1(); function2(); function3(); } That's correct. However, since the script is using external communication, other scripts that are listening for those messages will begin execution even before function1 has finished, because those other scripts are independent of it. 1 Link to comment Share on other sites More sharing options...
Xander Lopez Posted January 4, 2020 Author Share Posted January 4, 2020 Thanks for your explanation @Wulfie Reanimator I just did some couple testing and it appears to be that what you said is correct. (this makes my life a lot easier) I found the cause of my problem being originating from one of the llRegionSayTo. 1 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