Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Name previously defined in scope?

Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
08-17-2008 14:07
Now fixed
.. except it isn't !

I fixed the stupid mistake that revochen pointed out, but the damn thing won't turn off. Help, please!

If anyone can suggest a way of making my piston turn on and off, I would be most grateful.

CODE

integer moving = 1;
integer forward = TRUE;
default
{

state_entry()
{
}
touch_start(integer touched)
{
state on;
}
}
state on
{
state_entry()
{
while (moving >0)
{
if (forward == TRUE)
{
integer x;
for (x = 0; x < 5; x++)
{
llSetPos(llGetPos()+ <0.1,0,0>);
}
forward = FALSE;
}
if (forward == FALSE)
{
integer x;
for (x = 0; x < 5; x++)
{
llSetPos(llGetPos()- <0.1,0,0>);
}
forward = TRUE;
}
}


}
touch_start(integer touched)
{
state default;
}

}
revochen Mayne
...says
Join date: 14 Nov 2006
Posts: 198
08-17-2008 14:11
Hi Innula :)
Probably its because you're using the same name ("on";) for an integer variable and a state that causes the compiler to confuse.
Change the integer variables or states name and the script should work fine
=)
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
08-17-2008 14:22
Thanks.. I had copied and pasted a bit of code from a previous version and stupidly failed to spot it.
Haruki Watanabe
llSLCrash(void);
Join date: 28 Mar 2007
Posts: 434
08-17-2008 15:26
just a try :)

CODE

integer moving = 1;
integer forward = TRUE;
default
{

state_entry()
{
}

touch_start(integer touched)
{
moving = 1; // Without this, the on-state won't do
// anything, since you check for 'moving == 1' there
state on;
}
}

state on
{
state_entry()
{
integer x;

while (moving == 1)
{
if (forward == TRUE)
{
for (x = 0; x < 5; x++)
{
llSetPos(llGetPos()+ <0.1,0,0>);
}
forward = FALSE;
}else if (forward == FALSE)
{
for (x = 0; x < 5; x++)
{
llSetPos(llGetPos()- <0.1,0,0>);
}
forward = TRUE;
}
}
}

touch_start(integer touched)
{
moving = 0;
state default;
}

}



you used two 'if'-statements - but in the first one, you set forward to FALSE after the loop. In this particular case, this was working as the second 'if'-statement returned true as well, thus, the object moved back again. But this can be a pitfall in other circumstances, so you'd better use an «else if» for the second statement (sometimes, the second case doesn't need to take effect right after the first one, but the way you did it, it will)...
(kinda tired and don't have an example ready right now...)

HTH
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
08-17-2008 15:42
Thanks, but it's still not stopping. The problem seems to be to get it to register the touch after it's started moving and it's in the "while" part. I've put llOwnerSay("Touched";); into the second touch_start, and it's not detecting it.

It's getting late for me, too, and I'll have a play with work-rounds tomorrow, but it seems as if it should be easy enough. I can make it start and stop moving in one direction easily enough, and I can change directions, but getting it to go in and out continually, like a piston, until I stop it is proving remarkably challenging, at least for me.
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
08-18-2008 03:21
From: Innula Zenovka
Now fixed
.. except it isn't !

I fixed the stupid mistake that revochen pointed out, but the damn thing won't turn off. Help, please!

If anyone can suggest a way of making my piston turn on and off, I would be most grateful.

CODE

integer moving = 1;
integer forward = TRUE;
default
{

state_entry()
{
}
touch_start(integer touched)
{
state on;
}
}
state on
{
state_entry()
{
while (moving >0)
{
if (forward == TRUE)
{
integer x;
for (x = 0; x < 5; x++)
{
llSetPos(llGetPos()+ <0.1,0,0>);
}
forward = FALSE;
}
if (forward == FALSE)
{
integer x;
for (x = 0; x < 5; x++)
{
llSetPos(llGetPos()- <0.1,0,0>);
}
forward = TRUE;
}
}


}
touch_start(integer touched)
{
state default;
}

}

The way this code is made the simulator never gets one chance to leave the 'state_entry()' event handler. It is stuck as long as 'moving' is TRUE, which is forever:)
You will need some kind of event handler that does not do that. The following code utilizes a timer event that is concluded each time the piston is at an end position:
CODE

integer forward = TRUE;

default
{
state_entry()
{
llSetTimerEvent( 0.0 );
}
touch_start(integer touched)
{
state on;
}
}

state on
{
state_entry()
{
llSetTimerEvent( 0.1 );
}

timer()
{
vector increment = < 0.1, 0.0, 0.0>;
if (!forward) increment = < -0.1, 0.0, 0.0>;
integer x;
for (x = 0; x < 5; x++)
{
llSetPos(llGetPos()+ increment);
}
forward = !forward;
}

touch_start(integer touched)
{
state default;
}
}
_____________________
From Studio Dora
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
08-18-2008 05:42
Thank you so much, Dora. That works a treat. I guessed it must have to break off to check every now and again if it had been turned off, but I couldn't see a way to do it. Now I know, and it will so useful for other applications, too. I am so grateful; thank you again.