I'd like to combine two llSetPrimitiveParams scripts to make a retractable blanket with a cut cylinder (path cut 0.5 and 1.0). The first script is a touch_start script to make a hole for a door, that I found on these forums. The second script is the script for scaling and repositioning a cylinder. The second script is fine, but after touch_start the prim jumps back in its original position. So there is no second touch_start event.
Because the two scripts look so different to me, I don't know how to combine the two. What I would like is that the blanket is scaled and repositioned, but stays in that new position until the user clicks it again. Then it should go back to the original scale and position again.
I have looked hard to find similarities in the script, but I really don't know how to combine the two. I hope somebody can help.
SCRIPT 1 (make a hole in the prim):
CODE
integer trigger;
float i;
openBox()
{
trigger = 1;
do
{
i = i - 0.05;
llSetPrimitiveParams
([
PRIM_TYPE, 0,
//integer hole_shape, vector cut, float hollow, vector twist,
//Possible values for hole_shape are: PRIM_HOLE_DEFAULT, PRIM_HOLE_CIRCLE, PRIM_HOLE_SQUARE, PRIM_HOLE_TRIANGLE
PRIM_HOLE_CIRCLE, <0.0, 1.0, 0.0>, i, <0.0, 0.0, 0.0>,
//vector top_size, vector top_shear
<1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>
]);
}
while (i >= 0.0);
}
closeBox()
{
trigger = 0;
do
{
i = i + 0.05;
llSetPrimitiveParams
([
PRIM_TYPE, 0,
//integer hole_shape, vector cut, float hollow, vector twist,
//Possible values for hole_shape are: PRIM_HOLE_DEFAULT, PRIM_HOLE_CIRCLE, PRIM_HOLE_SQUARE, PRIM_HOLE_TRIANGLE
PRIM_HOLE_CIRCLE, <0.0, 1.0, 0.0>, i, <0.0, 0.0, 0.0>,
//vector top_size, vector top_shear
<1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>
]);
}
while (i <= 1.0);
}
default
{
state_entry()
{
i = 0.5;
closeBox();
}
touch_start(integer total_number)
{
if (trigger == 0) openBox();
else closeBox();
}
}
SCRIPT 2 (retractable blanket without second touch_start):
CODE
integer counter;
vector startScale;
vector startPos;
// Note: this represents the direction (1 or -1)
// divided by 2 because we only want
// to move half of the scale amount to keep
// one side in place. (we're just pre-calculating this)
float scaleFrac = -0.5; // which way to scale, 0.5 or -0.5
float tick = 0.2; // time for each change, must be > 0.2
integer channel = 2468; // channel to listen for start/reset
start()
{
if (counter != 0) // b ail if already running
return;
startScale = llGetScale();
startPos = llGetLocalPos();
counter = 0;
llSetTimerEvent( tick );
}
reset()
{
llSay(channel, "reset");
// restore only if script was triggered
if (startScale != ZERO_VECTOR && startPos != ZERO_VECTOR)
llSetPrimitiveParams( [PRIM_SIZE, startScale,
PRIM_POSITION, startPos] );
llResetScript();
}
default
{
state_entry()
{
counter = 0;
llListen(channel, "", "", "start");
llListen(channel + 1, "", "", "reset");
}
touch_start(integer total_number)
{
start();
}
listen(integer chan, string name, key id, string msg)
{
if (chan == channel)
start();
if (chan == channel + 1)
reset();
}
timer()
{
counter = counter + 1;
float seconds = tick * counter;
if ( seconds > 10 )
reset(); // restores and resets the script
vector scalevec = <0.0, 0.0, 0.2>; // direction of scaling
scalevec = scalevec * seconds;
vector newScale = startScale + scalevec;
rotation rot = llGetLocalRot();
vector newPos = startPos + ( scalevec * scaleFrac * rot );
llSetPrimitiveParams( [PRIM_SIZE, newScale,
PRIM_POSITION, newPos] );
}
}