|
Mickey James
Registered User
Join date: 4 Nov 2006
Posts: 334
|
10-25-2007 21:22
I'm mostly done with a script but I want to build a safeguard into it and everything I've tried so far has failed.
The object in question is supposed to interact with an avatar in the following way:
1. Object is in closed position
2. TOUCH Object moves to open position
3. SIT Avatar sits and object returns to closed position
4. TOUCH Object moves to open position
5. STAND UP Avatar stands and object returns to closed position. Script goes to default state.
All that works fine. But if the Avatar stands while the object is in the closed position (uses STAND UP instead of TOUCH in step four) then the object moves to what would be the closed position, except since it was never opened, it ends up misplaced and you have to drag it back to the closed position.
So what I would like to have is a sequence that would return the script to the default state without moving the object if the avatar stands at the wrong time. Nothing I've tried (mostly a variety of if-else statements) has worked.
How do I do this?
|
|
Day Oh
Registered User
Join date: 3 Feb 2007
Posts: 1,257
|
10-26-2007 01:42
I'm thinking you just need to keep track of whether it's open or closed, like with a TRUE/FALSE integer, and avoid closing unless open
|
|
Haravikk Mistral
Registered User
Join date: 8 Oct 2005
Posts: 2,482
|
10-26-2007 06:20
My preferred way is to use states like so: default { state_entry() { llSetPos(<1.0, 2.0, 3.0>); // The 'closed' position }
touch_start(integer x) { state open; } }
state open { state_entry() { llSetPos(<3.0, 2.0, 1.0>); // The 'open' positon llSetSitTarget(<1.0, 2.0, 3.0>, ZERO_ROTATION); // Where the avatar sits on this }
changed(integer x) { if ((x & CHANGED_LINK) && (llAvatarOnSitTarget() != NULL_KEY)) state default; }
touch_start(integer x) { state default; } }Something along those lines anyway. Since your item has only a limited set of clearly defined states then it makes more sense than storing integers, and allows you to make your code much neater.
_____________________
Computer (Mac Pro): 2 x Quad Core 3.2ghz Xeon 10gb DDR2 800mhz FB-DIMMS 4 x 750gb, 32mb cache hard-drives (RAID-0/striped) NVidia GeForce 8800GT (512mb)
|
|
Stephen Zenith
Registered User
Join date: 15 May 2006
Posts: 1,029
|
10-26-2007 06:24
From: Haravikk Mistral My preferred way is to use states like so: default { state_entry() { llSetPos(<1.0, 2.0, 3.0>); // The 'closed' position }
touch_start(integer x) { state open; } }
state open { state_entry() { llSetPos(<3.0, 2.0, 1.0>); // The 'open' positon llSetSitTarget(<1.0, 2.0, 3.0>, ZERO_ROTATION); // Where the avatar sits on this }
changed(integer x) { if ((x & CHANGED_LINK) && (llAvatarOnSitTarget() != NULL_KEY)) state default; }
touch_start(integer x) { state default; } }Something along those lines anyway. Since your item has only a limited set of clearly defined states then it makes more sense than storing integers, and allows you to make your code much neater. Plus, it allows you much greater control over how you get into each state. You can guarantee that the only way code in the open state can execute is after you've called "state open;" . It also ensures it does the right thing on a script reset or a copy being taken.
|
|
Mickey James
Registered User
Join date: 4 Nov 2006
Posts: 334
|
10-26-2007 15:54
I think that's solved it. Thanks!
|