Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Script for making an object rise?

a lost user
Join date: ?
Posts: ?
08-15-2005 10:53
Hi, I'm a relative newbie to SL, and this is my first post to the forum, so please be gentle. :)

I don't really know anything about scripts yet, but this seems like sucha common idea, that I'd be surprised if someone hadn't made it already. Basically I've built an underground area to my house that's accessible through a hidden opening under a rug. What I'd like to do is click on an object, like a picture on the wall, and have the rug rise up about three meters, revealing th opening underneath. Then with another click, close it back. Is this doable? And if it already exists, does someone have it or know where I can find it? It'd be much appreciated.
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
08-15-2005 11:30
For the "Secret Switch":

CODE
default
{
touch_start(integer total_number)
{
if( llGetOwner() == llDetectedKey(0) )
{
llShout(90902, "sesame");
}
}
}


and for the "Secret Floor/wall/ceiling/rock/lemon tree":
CODE
vector door_offset = <0,0,5>; // distance to move from start popsition(closed) to open.

float steps = 10.0; // number of steps to take to get there

// Variables
vector closed;
vector opened;

// Functions
moveit(vector target)
{
llLoopSound("f728e06c-77f0-3071-87da-9e731783f543", 1.0);
vector offset = (target - llGetPos()) / steps;
while ( llVecDist(llGetPos(), target) > 0.1 )
{
llSetPos(llGetPos() + offset);
}
llSetPos(target);
llPlaySound("8202deb3-ad04-66a0-f334-a6a9c56312df", 1.0);
llSleep(1);
llStopSound();
}

// States

default
{
state_entry()
{
closed = llGetPos();
opened = closed + door_offset;
llSay(0, "Reset!");
state close;
}

on_rez(integer n)
{
llResetScript();
}
}

state close
{
state_entry()
{
moveit(closed);
llListen(90902, "", NULL_KEY, "");
}

on_rez(integer n)
{
llResetScript();
}

listen(integer chan, string name, key id, string msg)
{
if ( msg == "sesame" && llGetOwnerKey(id) == llGetOwner() )
{
state open;
}
else if ( msg == "reset" && id == llGetOwner() )
{
llResetScript();
}
}
}

state open
{
state_entry()
{
moveit(opened);
llListen(90902, "", NULL_KEY, "");
}

on_rez(integer n)
{
llResetScript();
}

listen(integer chan, string name, key id, string msg)
{
if ( msg == "sesame" && llGetOwnerKey(id) == llGetOwner() )
{
state close;
}
else if ( msg == "reset" && id == llGetOwner() )
{
llResetScript();
}
}
}


Note the UUIDs in the sound library calls are of a grinding stone and a thump sound, you can replace those with whatever you like, of course.

These are compiled and test fine in world. I'll plonk a copy on ya.

Note you can move the "Secret Wall" to a new "closed" position and say /90902reset in chat and it will change it's closed position.
_____________________
a lost user
Join date: ?
Posts: ?
08-15-2005 19:02
Many thanks Jillian! I was a bit confused at first, but I drug them onto the objects and it works great! Thanks a million!

One small question though. Is it possible to lower how far the second object rises by just a bit?
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
08-15-2005 21:13
Change the value of the first line.
CODE
vector door_offset = <0,0,5>; // distance to move from start popsition(closed) to open.
You wrote "about three meters", but she put "5" meters. Jillian always prefers higher! ;)
_____________________
:) Seagel Neville :)
a lost user
Join date: ?
Posts: ?
08-16-2005 08:20
Ah, it's right there on the first line. Maybe if I'd actually LOOK at the thing...
a lost user
Join date: ?
Posts: ?
08-16-2005 20:43
Uh-oh, one last question and I'll leave you guys alone.

How do I go about getting rid of the constant stone grinding sound the script makes? I tried deleting the 'playsound' line but get an error message.
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
08-16-2005 21:03
You have to delete 4 lines.

1. llLoopSound("f728e06c-77f0-3071-87da-9e731783f543", 1.0);
2. llPlaySound("8202deb3-ad04-66a0-f334-a6a9c56312df", 1.0);
3. llSleep(1);
4. llStopSound();

But I recommend you should just put "//" (comment out) head of those lines rather than delete them so that you can put them back soon.
_____________________
:) Seagel Neville :)
a lost user
Join date: ?
Posts: ?
08-16-2005 21:20
Ah okay. I'll try that when I get home from work in the morning.

Thanks for your kindness and patience with a script newbie. :)
a lost user
Join date: ?
Posts: ?
08-17-2005 07:28
Just an aside to playing sounds.. if you don't need to play the sound at 100% volume, don't. If playing the sound at 50% volume works for the application you are using the sound for, then use 50% volume. There's a lot of sounds in the game that can be heard halfway across the sim when people use them, simply because the volume is set too high. Even pushing a sound 64 metres when it only really needs to go 10 metres is a bit of overkill.

llPlaySound("name of sound", 1.0); = 100% volume
llPlaySound("name of sound", 0.5); = 50% volume
llPlaySound("name of sound", 0.25); = 25% volume

and so on..
Salen Welesa
Kupo? Dook?
Join date: 13 Jul 2005
Posts: 65
08-17-2005 18:37
Hmm. I tried these scripts, and while the moving of the item seems to work fine if I say "/90902 sesame", the touch script doesn't seem to be working. Is there something I've messed up? I tried to test it out by changing the 90902 to 0, just to see if it was working, and it said it fine, but once I changed it back to 90902, it still wouldn't cause the object to move.

Any suggestions on how to fix this, since I'm trying to use the basics of the scripts to make a sliding cockpit canopy for my aircraft. It works pretty well for sliding forward though. But the clicking part doesn't want to work.
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
08-17-2005 19:09
From: Salen Welesa
Hmm. I tried these scripts, and while the moving of the item seems to work fine if I say "/90902 sesame", the touch script doesn't seem to be working. Is there something I've messed up? I tried to test it out by changing the 90902 to 0, just to see if it was working, and it said it fine, but once I changed it back to 90902, it still wouldn't cause the object to move.

Any suggestions on how to fix this, since I'm trying to use the basics of the scripts to make a sliding cockpit canopy for my aircraft. It works pretty well for sliding forward though. But the clicking part doesn't want to work.
This isn't terribly good for child prim movement anyway. I can't say for certain why the call isn't working for you, but it's a very inefficient way to go about it anyway.

Try this:
CODE
 vector door_offset = <1,0,0>; // distance to move from start popsition(closed) to open.

float steps = 10.0; // number of steps to take to get there

// Variables
vector closed;
vector opened;

// Functions
moveit(vector target)
{
llLoopSound("f728e06c-77f0-3071-87da-9e731783f543", 1.0);
vector offset = (target - llGetLocalPos()) / steps;
while ( llVecDist(llGetLocalPos(), target) > 0.1 )
{
llSetPos(llGetLocalPos() + offset);
}
llSetPos(target);
llPlaySound("8202deb3-ad04-66a0-f334-a6a9c56312df", 1.0);
llSleep(1);
llStopSound();
}

// States

default
{
state_entry()
{
closed = llGetLocalPos();
opened = closed + door_offset;
llSay(0, "Reset!");
state close;
}

on_rez(integer n)
{
llResetScript();
}
}

state close
{
state_entry()
{
moveit(closed);
}

on_rez(integer n)
{
llResetScript();
}

touch_start(integer n)
{
if ( llDetectedKey(0) == llGetOwner() )
{
state open;
}
}
}

state open
{
state_entry()
{
moveit(opened);
}

on_rez(integer n)
{
llResetScript();
}

touch_start(integer n)
{
if ( llDetectedKey(0) == llGetOwner() )
{
state close;
}
}
}
Note: Still has the sone grind and thump in it. You can replace those sounds easily. :)
_____________________
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
08-17-2005 19:14
llShout(90902, "sesame";); corresponds to llListen(90902, "", NULL_KEY, "";);. If llShout(0, "sesame";); works and you can hear it shout, change also llListen's channel number and see how it's going. And what about "1", too.
I don't know what is wrong as far as I read the script.
_____________________
:) Seagel Neville :)
Salen Welesa
Kupo? Dook?
Join date: 13 Jul 2005
Posts: 65
08-18-2005 05:06
Thanks Jillian. I'll try that altered script when I get home later. Removing the sound shouldn't be that hard, since I did just that, yesterday.
a lost user
Join date: ?
Posts: ?
08-18-2005 20:18
Well brother I'm stumped. I've added the '//'s, switched the volume to .10, and even deleted the files altogether, but I'm still getting a constant stone grinding sound. I haven't got a clue as to what's going on and it's making me nuts! Currently looking at other objects in my house looking for hidden sound scripts, but so far no luck. Could someone have planted a hidden script bomb on my property I wonder?

Would any of you script wizards be able to stop by my place in game to have a look?
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
08-18-2005 20:55
Put this in a new script, then insert the script into the prim:

CODE
default
{
state_entry()
{
llStopSound();
llRemoveInventory(llGetScriptName());
}
}


The script will stop the sound, then remove itself from the prim.
_____________________
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
08-18-2005 21:40
:eek: Jillian, I'm sorry? I didn't understand this. What's happening?
Does this have something to do with using keys of sounds?
_____________________
:) Seagel Neville :)
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
08-18-2005 21:44
Oh, yeah. I should explain. :o

llLoopSound actually changes the parameters of the prim. Like particles or floaty text, you can set a sound playing in a prim with a script, then remove the script and the sound goes merrily on.

This is probably what happened to Tetrae. Due to lag or some other circumstance, the llStopSound didn't take effect one time she used it. And then she edited out all the sound library calls - so the sound keeps going.

So, the script I wrote there will stop the sound - change the prim parameters back to a silent prim - and then delete itself to get out of the way.
_____________________
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
08-18-2005 22:23
Heh, yeah, I've ever experienced this on float texts. I got it. Thank you. I've learnd again. ;)
_____________________
:) Seagel Neville :)
a lost user
Join date: ?
Posts: ?
08-20-2005 16:34
Problem is fixed finally. Thanks guys!