Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Sliding door - Separate 1 function into 2

Jack Tigerpaw
Registered User
Join date: 19 Nov 2007
Posts: 21
01-13-2008 07:53
Hi, new here and somewhat new to scripting. Hope someone can offer help.

I would like to separate this one function into the two functions listed below.
From: someone
integer iSteps = 15;
vector vOffset = <-0.20, 0, 0.0>;

open()
{
integer i;
vector basepos = llGetPos();
for (i = 0; i < iSteps; i++)
{
llSetPos(basepos + i*vOffset);
}
vOffset *= -1;
// llSleep(fOpenTime); Not needed -
// other method in other script
// for open time
basepos = llGetPos();
for (i = 0; i < iSteps; i++)
{
llSetPos(basepos + i*vOffset);
}
vOffset *= -1;
}


Into these two functions:
From: someone
//- - - - - - - - - - - - - - - -
integer open(string av_name) // Opens the door.
{
if (open_sound != "";) llTriggerSound(open_sound, 0.5);
if (open_message != "";) llSay(0, replace(open_message,"nn",av_name));

// vv Replace this snippet with custom code to open the door vv



return TRUE;
}


//- - - - - - - - - - - - - - - -
integer close(string av_name) // Closes the door.
{
if (close_sound != "";) llTriggerSound(close_sound, 0.5);
if (close_message != "";) llSay(0, replace(close_message,"nn",av_name));

// vv Replace this snippet with custom code to close the door vv



return FALSE;
}
Jack Tigerpaw
Registered User
Join date: 19 Nov 2007
Posts: 21
Is this correct?
01-13-2008 07:54
Is this correct?
Note to self: fOpenTime is not needed (I think) there is another method for how long the door stays open.
From: someone
//- - - - - - - - - - - - - - - -
integer open(string av_name) // Opens the door.
{
if (open_sound != "";) llTriggerSound(open_sound, 0.5);
if (open_message != "";) llSay(0, replace(open_message,"nn",av_name));

// vv Replace this snippet with custom code to open the door vv
integer i;
vector basepos = llGetPos();
for (i = 0; i < iSteps; i++)
{
llSetPos(basepos + i*vOffset);
}

return TRUE;
}


//- - - - - - - - - - - - - - - -
integer close(string av_name) // Closes the door.
{
if (close_sound != "";) llTriggerSound(close_sound, 0.5);
if (close_message != "";) llSay(0, replace(close_message,"nn",av_name));

// vv Replace this snippet with custom code to close the door vv
vOffset *= -1;
basepos = llGetPos();
for (i = 0; i < iSteps; i++)
{
llSetPos(basepos + i*vOffset);
}
vOffset *= -1;

return FALSE;
}
Jack Tigerpaw
Registered User
Join date: 19 Nov 2007
Posts: 21
01-13-2008 08:14
Do I really need this:
From: someone
if (llGetPos() != vBase) {
llSetTimerEvent(5);
} else {
bMove = FALSE;
}


if I already have the timer function as this?
From: someone
timer()
{
stopListening();
if (door_open){
door_open = close("the script";);
}
}


Or should it be in the timer function too somehow?
Jack Tigerpaw
Registered User
Join date: 19 Nov 2007
Posts: 21
01-14-2008 07:41
I found I have to re-declare

integer i;
vector basepos = llGetPos();

In both functions.

Is there some other/better way of doing this?

I find it hard to believe nobody knows or can offer any tips on this. :(
Kidd Krasner
Registered User
Join date: 1 Jan 2007
Posts: 1,938
01-14-2008 09:06
For i, having a separate declaration in each function is the right thing to do.

For basepos, there's no way to tell without knowing how these functions are being used. It's certainly not wrong the way you have it. There might be circumstances in which it makes sense to have it as a global. My hunch, however, is that that would just make it more difficult for you unti you get more comfortable with scripting. So leave it as is for now.

Beyond this, perhaps you could ask something more specific? Your base note didn't actually ask any questions, so it's no surprise that there were no answers.