Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

can someone look at this newb script for me?

Octal Khan
Putting the Mod in Modern
Join date: 14 Feb 2004
Posts: 116
02-01-2006 19:26
hi all,

Im no scripting whiz, im just trying to move windows up and down when clicked to open them, but whenever I rez the house with the windows using this script somewhere new, they fly off into outerspace when clicked.

I thought GetLocalPos would solve all that when its rezzed for the first time but so far no joy...:/

thanks!

PS: if someone csan show me how to incorporate a rot into this as well id be forever grateful!
___________________________________________

integer on; //is the switch on?
integer touched = TRUE;
open()
{
llSay(0, "Opening";);
vector target = origpos + newpos;
while (llVecDist(llGetLocalPos(), target) > 0.001) llSetPos(target);
llSetTimerEvent(500);

}


close()
{
llSay(0, "Closing";);
vector target = origpos;
while (llVecDist(llGetLocalPos(), target) > 0.001) llSetPos(target);
llSetTimerEvent(0);
}


vector origpos;
vector newpos = <0,0,-1.35>;

default
{
state_entry()
{
origpos = llGetLocalPos();
}

timer()
{
close();
}

touch_start(integer total_number)
{
if (touched)
{
open();
}

else
{
close();
}
touched = !touched;
}

}
Jokey Domela
Registered User
Join date: 27 Jul 2005
Posts: 83
02-01-2006 19:50
reminder, scripts retain their variables even when picked up. May want an on_rez event to llResetScript();
Octal Khan
Putting the Mod in Modern
Join date: 14 Feb 2004
Posts: 116
02-02-2006 15:55
Thanks Jokey, that solved the rezzing issue, but now I have a new problem :)

Say the house is bought and the new owner rezzes it.

No problem so far, everything works great, but say they decide its in the wrong place and move it to the left.
Next time the window slide script (for example) is activated it thinks the GetLocalPos origin is still where it was when it was rezzed, and the window flies over there, instead of sliding up and down in its new origin.

Whats the best way around this? im sure others have run into this all the time and there must be a simple solution.

Thanks!

PS; i was thinking about including a "button" that would llResetScript all the related house scripts after they had finished re-positioning it....is this the wrong tack? If its the right tack how do i do it?
Folco Boffin
Mad Moo Cow Cultist
Join date: 27 Feb 2005
Posts: 66
02-02-2006 16:35
CODE
vector origpos;
vector newpos = <0,0,-1.35>;
integer gopen = FALSE;

open() {
llSay(0, "Opening");
gopen = TRUE;
origpos = llGetLocalPos();
vector target = origpos + newpos;
while (llVecDist(llGetLocalPos(), target) > 0.001) llSetPos(target);
llSetTimerEvent(500);
}


close() {
llSay(0, "Closing");
gopen = FALSE;
vector target = origpos;
while (llVecDist(llGetLocalPos(), target) > 0.001) llSetPos(target);
llSetTimerEvent(0);
}

default {
state_entry() {
origpos = llGetLocalPos();
}

on_rez(integer a) {
llResetScript();
}

timer() {
close();
}

touch_start(integer total_number) {
if (gopen) {
open();
} else {
close();
}
}
}


How's that work for you? It doesn't reset the script when moved, but it should just record where the window is when you open it.
If you want to reset it when you move, I think you want on_change, but I'm a litte occupied to go looking at the moment.
_____________________
^-^

Signed,
Gorgarath,
Whom in this game called Second Life,
plays the avatar Folco Boffin,
and in this game called First Life,
plays the avatar John McDonnell.
Octal Khan
Putting the Mod in Modern
Join date: 14 Feb 2004
Posts: 116
02-02-2006 18:28
thanks! that did the trick :o
Folco Boffin
Mad Moo Cow Cultist
Join date: 27 Feb 2005
Posts: 66
02-03-2006 07:07
There's better ways than what I posted, but it was all I could think of off the top of my head while attempting to pay attention to the conversation on the phone. :D

If they move it while the window is open, there's gonna be some issues.

Might want to change it from moving to origpos and have it move the inverse of newpos? Or have it reset when change is detected... but I'm not sure if moving it would trigger the change event or not...

You could always do something like
CODE
vector gpos;
open() {
llSay(0, "Opening");
gopen = TRUE;
origpos = llGetLocalPos();
vector target = origpos + newpos;
while (llVecDist(llGetLocalPos(), target) > 0.001) llSetPos(target);
gpos = llGetLocalPos();
llSetTimerEvent(500);
}

close() {
llSay(0, "Closing");
gopen = FALSE;
if (gpos != llGetLocalPos())
vector target = llGetLocalPos() - newpos;
else
vector target = origpos;
while (llVecDist(llGetLocalPos(), target) > 0.001) llSetPos(target);
llSetTimerEvent(0);
}


I haven't tested this but in my head it would work and wouldn't cause problems if you moved it while the windows were open. Though looking at the code it seems really bloated and could probabally be writen much much better.
There's too much repititon I think...


EDIT>> That looks a bit better. Still can probabally be done a lot better.
_____________________
^-^

Signed,
Gorgarath,
Whom in this game called Second Life,
plays the avatar Folco Boffin,
and in this game called First Life,
plays the avatar John McDonnell.