|
CoyoteAngel Dimsum
Registered User
Join date: 26 Mar 2006
Posts: 124
|
08-19-2007 20:23
I'm sending a start-doing-something linkmessage to a child prim. Obviously (below), the loop just runs forever. I've peeked and poked at events and states documentation and am more confused than ever. I want the root object to tell various linked child objects (tasks?) to start doing things (move themselves about, let's say) and then not have to pay attention to them until I want them to do something else. Do I have the right design? If so, is there some way to allow the local properties to be updated while the loop is executing? If not, what am I missing? Thank you. Child pseudo-code: integer IS_DOING_SOMETHING = FALSE; start_doing_something(){ integer x = 0; IS_DOING_SOMETHING = TRUE; while (IS_DOING_SOMETHING){ // do something boring, wait, do the opposite // is there some way to yield execution and force the objects properties to be updated or other methods to execute? } ; } stop_doing_something(){ IS_DOING_SOMETHING = FALSE; } default { link_message(integer send, integer iMsg, string msg, key id) { if ( iMsg == 3 ) { start_doing_something(); } else if ( iMsg == 4 ) { stop_doing_something(); } } }
_____________________
-CoyoteAngel Dimsum/Lynne Wu
|
|
Damanios Thetan
looking in
Join date: 6 Mar 2004
Posts: 992
|
08-19-2007 21:10
Why not use a timer event instead of an endless busy loop? default { link_message(integer send, integer iMsg, string msg, key id) { if ( iMsg == 3 ) { llSetTimerEvent(1.0); // do something every second } else if ( iMsg == 4 ) { llSetTimerEvent(0); // stop doing something }
timer() { // do something }
}
|
|
CoyoteAngel Dimsum
Registered User
Join date: 26 Mar 2006
Posts: 124
|
08-19-2007 22:50
No reason that I know of, hence the questions.  In my regular work I'd try to avoid timers, since the actions in question are triggered infrequently, and timers would not be a good use of resources in that environment. In this case, though, the something that happens is wing flapping, and I have up to four of them working at once, worst case, and need them relatively synchronized. I'll try timers to see about the resource consumption and synch issues. Thank you for the suggestion. Each wing would flap at most twice/second in the following cycle: Start flapping( primaries to up position primaries to down position wait .2 seconds primaries to up position wait .4 seconds All of this is then synchronized with intermittent X,Y,Z forces of varying strengths along with buoyancy adjustments. That's the theory, at least.
_____________________
-CoyoteAngel Dimsum/Lynne Wu
|
|
Ed Gobo
ed44's alt
Join date: 20 Jun 2006
Posts: 220
|
08-20-2007 02:23
lSetPos and llSetRot have .2 sec delays built into their scripts. Even in a non laggy area you might find it hard to keep up.
Then again, perhaps you are using physical scripts?
|
|
Milambus Oh
Registered User
Join date: 6 Apr 2007
Posts: 224
|
08-20-2007 06:26
You need to use a timer. Scripts can only be in one event at a time, meaning that until your while loop stops executing the script can not respond to another linked message... which in effect means the look can never end.
A timer would break execution after each cycle, allowing the script to respond to other events and eventually allow the timer to stop executing.
Alternatively, you need to have your while loop monitor a property of the Prim that the root prim can alter via llSetLinkPrimitiveParams().
|