Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

while loop

Zeta Eizenstark
Registered User
Join date: 20 Aug 2008
Posts: 79
06-09-2009 08:49
Is it possible to get out of a while loop by touching it again. I want an item to constantly move around when touched but then stop moving if touched again.
something like this....
CODE

integer x;
default
{
touch_start(integer total_number)
{
while(x != 100)
{
llSetPos(llGetPos() + <4,0,0>);
llSetPos(llGetPos() + <0,4,0>);
llSetPos(llGetPos() + <-4,0,0>);
llSetPos(llGetPos() + <0,-4,0>);
}
}
}

so when i touched in infinitly move around but I want it to stop if its touched again. If it can be done in an easier way, please do tell. Thanks.
Jack Abraham
Lantern By Day
Join date: 11 Apr 2008
Posts: 113
06-09-2009 08:55
I'd suggest on the first touch you change states to a moving state, do your moves on a timer, and if touched while in the moving state change back to the immobile default state. Or something like that.

As far as I know you wouldn't be able to detect the touch while you're still in the touch_start event.
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
06-09-2009 09:16
You never set or change the variable x.

It will get a value of 0 by default and "while(x != 100)" will always be true..

What you probably want to do is "while (x++ != 100)" so it increments each time.
_____________________
Sick of sims locking up every time somebody TPs in? Vote for SVC-3895!!!
- Go here: https://jira.secondlife.com/browse/SVC-3895
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
06-09-2009 09:17
From: Jack Abraham
As far as I know you wouldn't be able to detect the touch while you're still in the touch_start event.

Yep.
_____________________
Sick of sims locking up every time somebody TPs in? Vote for SVC-3895!!!
- Go here: https://jira.secondlife.com/browse/SVC-3895
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
06-09-2009 11:08
Yeah. Changing states isn't even necessary really. Just start and stop the timer as appropriate using non-zero and zero values in llSetTimerEvent(), respectively. This is nicer on both the script (because it can continue to receive events) and the server (because after every small bit of processing you return control explicily instead of making the server wrest control back when your handler has taken too long). It may have a down-side of decreased smoothness/performance, but hopefully you can play with that and make it work sufficiently for your application.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
06-09-2009 17:17
shouldn't have any smoothness issues over just the function call since times have the same minimum trigger time as the setPos call, it may need a check to see if it should be running though to prevent a queued timer even from running after the click to turn of has been queued (a one in four occurrence with that code?)

just insert
if (timer_value){
// movement code
}

and use timer value as the trigger for the timer.
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Zeta Eizenstark
Registered User
Join date: 20 Aug 2008
Posts: 79
06-10-2009 06:15
Thanks to all who responded. I have it up working now. I took to the path of double states. It works really nice.