Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Ups and Downs

Ford Static
Registered User
Join date: 4 Dec 2009
Posts: 12
01-27-2010 17:51
Hi folks,

Could one of you clever people suggest where I'm going wrong? The following script is supposed to do nothing more than make a prim go up if it's below a certain height and down if it's above a certain height. Annoyingly, it seems to really, really want to go down.

It's probably hopelessly over-complicated for what it is, but I've been fiddling with it all evening, and should have gone to bed hours ago. Thanks in advance.


// Unbelievably annoying up/down script
// by Ford "Go up, damn you, for the love of all that's merciful, just go up" Static

vector startPosition;
vector newPosition;
vector targetPositionA;
vector targetPositionB;
integer isup = FALSE;

default
{
state_entry()
{
startPosition = llGetPos();
targetPositionA = (startPosition + <0.0, 0.0, 8.0>;);
targetPositionB = (startPosition + <0.0, 0.0, -8.0>;);
}

touch_start(integer total_number)
{
if (isup = FALSE)
{
llSay(0, "False";);
state moveup;
}

else
{
llSay(0, "True";);
state movedown;
}
}
}

state moveup
{
state_entry()
{
newPosition = llGetPos();

if (newPosition.z < targetPositionA.z)
{
llSetPos(newPosition + <0.0, 0.0, 0.2>;);
state newupstate;
}

else
{
isup = TRUE;
state default;
}
}
}

state newupstate
{
state_entry()
{
state moveup;
}
}

state movedown
{
state_entry()
{
newPosition = llGetPos();

if (newPosition.z > targetPositionB.z)
{
llSetPos(newPosition + <0.0, 0.0, -0.2>;);
state newdownstate;
}

else
{
isup = FALSE;
state default;
}

state newdownstate;
}
}

state newdownstate
{
state_entry()
{
state movedown;
}
}
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
01-27-2010 18:04
if (isup = FALSE)

Should be

if (isup == FALSE)

or can be

if (!isup)
2fast4u Nabob
SL-ice.net
Join date: 28 Dec 2005
Posts: 542
01-27-2010 19:21
From: Talarus Luan
Should be if (isup == FALSE)

or can be

if (!isup)


I think this is a common mistake and really hard to spot. You can make it easier to find problems like this by having the compiler help you a little.

Reverse the order of the operands inside the IF statement - put the constant on the left side of the == like this:

if( FALSE == isup)
//etc..

If you use a single equals symbol by accident the compiler will complain with a syntax error when the script compiles - so the compiler does a bit of error checking for you.

This approach only works when comparing to constants like FALSE, numbers etc. It's handy because you don't end up wasting lots of time on trying to find problems like this - you basically force the compiler to check for you.

-2fast
Ford Static
Registered User
Join date: 4 Dec 2009
Posts: 12
01-28-2010 11:21
Brilliant. Thanks a million, both. Hugely appreciated.

Ford.
Ford Static
Registered User
Join date: 4 Dec 2009
Posts: 12
01-28-2010 15:32
Hello, me again.

So the up/down thing is resolved, which is excellent, and I've gone on to turn the thing into a reasonably functioning elevator. But...

I don't want to use an elevator sitting down. That's crazy. Who sits in an elevator, except elevator operators in 1930s New York? So I've added a line using llStartAnimation("stand";), and that's fine going up.

But having reached the top of the elevator, giddy with success at this remarkable accomplishment, I took the trip back down to universal acclaim and glory. At which point my legs folded up like a broken deckchair. Painful to watch, let me tell you.

Now I don't like to run crying to a forum every time I have a setback. I like to spend two, three, four hours doing my research, fail dismally, and then run crying to a forum. And this evening I discovered all sorts of interesting things about animations, one of which is that the standard "stand" pose doesn't "lock" avatar legs. "Surf" does, but it's not a great look for an elevator pose.

So I decided that I'd design my own animation, using QAvimator, of which I've heard good things. Unfortunately, it seems that installing QAvimator onto Ubuntu 9.10 is a mission on a par with getting that Mars buggy out of its hole. And I'm not a rocket scientist.

Having looked at some alternatives, including Blender (easy to install, apparently not so much for uploading) I've concluded that I should install WINE, then run QAvimator off that, which should allow me create my "locked legs" animation and run my elevator smoothly.

At which point I realised that this was probably an awful lot of work to solve a really minor problem. Does anyone know of a full perm "stand" animation that won't crumple on an elevator?

Ta.

- Ford

PS. I know there are a hundred and one elevator scripts out there, and yes, I'm fully aware that I'm reinventing the wheel. But I need to get to the wheel in order to reach the loom, internal combustion engine and space elevator. Which will bring me full circle. Like a wheel. I'll shut up now.
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
01-28-2010 15:59
That "folding" business has little or nothing to do with the particular animation used in the sit transport. They all do it occasionally. Just for the heck of it, try a few of the other internal animations that SL offers. In particular, try stand_1, stand_2, stand_3, and stand_4. Those and others are listed at .
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Ford Static
Registered User
Join date: 4 Dec 2009
Posts: 12
01-28-2010 16:29
Interesting. Strangely, the "stand" animations all seem to do the same thing, but "impatient" doesn't, and looks appropriate to the situation. Thanks for that, Rolig. If anyone else has anything to add, I'd be very interested to hear it.

Incidentally, I've got QAvimator running now, but only in the initial experimentation phase.

Cheers,

- Ford.
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
01-28-2010 16:43
The "crumpling" may well the the avatar colliding with something, there are some motions the viewer triggers in an attempt to keep the feet touching the floor. With no AO on, you can best see the effect if you stand on the side of a steep hill.

Things that might make a difference are making the elevator phantom if it's not already, or stopping the elevator a little higher so the avatar isn't running into any solids like the floor.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-28-2010 17:45
the legs aren't be animated in the built in stands, so they are free moving with inertia... you can see this by using a walk from an ao instead... get a custom stand animation and you should be all good.
_____________________
|
| . "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...
| -
Ford Static
Registered User
Join date: 4 Dec 2009
Posts: 12
01-28-2010 19:11
And thanks to both the Vs there. Fine ideas, both. In this case, Viktoria, I'm pretty sure I'm not touching anything - I have the elevator several metres above the floor for testing. Making it phantom is an interesting idea, though I think the problem lies in the initial definition of llSitTarget - my AV thinks his legs are still at his original start point (but I could be wrong).

Void, I'd gone down that route, and theoretically it's a perfectly workable solution, but I'm involved in a shared project and I can't find a single purveyor of fine animations with a no strings, full perm version.

Anyhoo, I think I've ironed out the bugs on what now seems to be a fairly happy script, so in case anyone's interested, here it is. I see no reason to change a catchy name once I've chosen one. As before, any comments or opinions gratefully received.

- Ford.


// Unbelievably annoying up/down script
// by Ford "Go up, damn you, for the love of all that's merciful, just go up" Static

vector startPosition;
vector newPosition;
vector targetPositionA;
vector targetPositionB;
integer isup = FALSE;

default
{
state_entry()
{
llSitTarget(<0,0,1>,<0,0,0,1>;);

if (FALSE == isup)
{
llSetSitText("Up";);
}

if (TRUE == isup)
{
llSetSitText("Down";);
}
}

changed(integer change)
{
if (change & CHANGED_LINK)
{
key agent = llAvatarOnSitTarget();

if (agent)
{
startPosition = llGetPos();
targetPositionA = (startPosition + <0.0, 0.0, 5.0>;);
targetPositionB = (startPosition + <0.0, 0.0, -5.0>;);
llRequestPermissions(agent, PERMISSION_TRIGGER_ANIMATION);
}
}
}

run_time_permissions(integer perm)
{
if (perm)
{
llStopAnimation("sit";);
llStartAnimation("impatient";);
state definemovement;
}
}
}

state definemovement
{
state_entry()
{
if (FALSE == isup)
{
state moveup;
}

if (TRUE == isup)
{
state movedown;
}
}
}

state moveup
{
state_entry()
{
newPosition = llGetPos();

if (newPosition.z < targetPositionA.z)
{
llSetPos(newPosition + <0.0, 0.0, 0.2>;);
state newupstate;
}

else
{
isup = TRUE;
key agent = llAvatarOnSitTarget();
llStopAnimation("impatient";);
llUnSit(agent);
state default;
}
}
}

state newupstate
{
state_entry()
{
state moveup;
}
}

state movedown
{
state_entry()
{
newPosition = llGetPos();

if (newPosition.z > targetPositionB.z)
{
llSetPos(newPosition + <0.0, 0.0, -0.2>;);
state newdownstate;
}

else
{
isup = FALSE;
key agent = llAvatarOnSitTarget();
llStopAnimation("impatient";);
llUnSit(agent);
state default;
}

state newdownstate;
}
}

state newdownstate
{
state_entry()
{
state movedown;
}
}
Alisha Matova
Too Old; Do Not Want!
Join date: 8 Mar 2007
Posts: 583
01-29-2010 11:14
I have a physical elevator that has been running for Ages. It is here : http://slurl.com/secondlife/Wild%20Rice/223/180/22 ,
and the script came out of this forum(with some modding). If your interested ill hand you a copy. =D