Jump to content

Timed script to change the hollow value of a prim


Queenship3001
 Share

You are about to reply to a thread that has been inactive for 2936 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

So t has been a LONG time since I've done any form of scripting and I find myself kind of relearning what I'm doing.

 

I wouldn't say I'm starting off with something basic either.

I have a sphere that's been cut in half and hollowed out a bit. I'm trying to create a script that will change the value for hollow after a set ammount of time, but the LSL wiki isn't being especially helpful today..

The script should do the following:

1: upon rez/attach (The sphere will be an attachment in time), the hollow value should be reset to a base value (e.g. 0.5)

2:Using a timer or something, the hollow value needs to change so it shrinks after a set amount of time.

3: After another set amount of time, the hollow value needs to go up again (We'll say it's going back up to 0.5).

 

If any of this sounds too vague just tell me and I'll try to specifiy my meaning. I'm trying to put in what I remember into a script now, but any help would be appreciated.

Link to comment
Share on other sites

 you need a timer flag , an init user function for on_rez and attach, and SLPPF ?

 

init(){  llSetLinkPrimitiveParamsFast(LINK_THIS, [      PRIM_TYPE, PRIM_TYPE_SPHERE,  0x00 ,<0.5,1.0,0.0>, 0.50, <0.0, 0.0,0.0>, <0.0,1.0,0.0>    ]);            llSetTimerEvent(5.0);  // first timer interval}integer flag;default{     attach(key id)    {        if (id)            { init();                    }           }     on_rez(integer start_param)    { init();    }    state_entry()    {            }    touch_start(integer total_number)    {           }    timer()    {        if(flag == 0)        {         llSetLinkPrimitiveParamsFast(LINK_THIS, [         PRIM_TYPE, PRIM_TYPE_SPHERE,  0x00 ,<0.5,1.0,0.0>, 0.25, <0.0, 0.0,0.0>, <0.0,1.0,0.0>    ]);        }                 if(flag == 1)        {         llSetLinkPrimitiveParamsFast(LINK_THIS, [         PRIM_TYPE, PRIM_TYPE_SPHERE,  0x00 ,<0.5,1.0,0.0>, 0.50, <0.0, 0.0,0.0>, <0.0,1.0,0.0>    ]);         return;        }                flag = 1;        llSetTimerEvent(10.0);  // second timer interval                }}

d

Link to comment
Share on other sites

The flag you need to concentrate on is PRIM_TYPE, which is followed by 

integer holeshape, vector cut, float hollow, vector twist, vector dimple

So since you're scripting a sphere, you might use 

llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_TYPE, PRIM_TYPE_SPHERE, 0, <0.0, 1.0, 0.0>,  <0.0, 0.0, 0.0>, <0.0, 1.0, 0.0>]);

Where N.N is a float between 0.0 (solid) and 0.95 (maximum hollowed).

I'm using llSetLinkPrimitiveParamsFast there, even though it's only a single prim, since it doesn't introduce any artificial delays.

Link to comment
Share on other sites

In regards to Xiija's reply, that is almost what I'm looking for, very very close. I don't actually need it to function for both on_rez and on_attach, I just use on_rez because it's easier to test the functionality of the script on a arge object rather than a small attachment. I change it later on.

 

By the looks of it, it cycled through changing the hole size from 0.5, to 0.25 and then back to 0.5, but only the one time. What I'm looking for needs to have this happen non-stop, switching between the two sizes every 5 seconds or so.

 

In reply to Innula, I did finally get it down after a little T&E, to at least figure out what I needed to set the hollow size lol.

vector cut = <0.5, 1.0, 0.0>;float hollow = 0.5;vector twist = <0.0, 0.0, 0.0>;vector dimple = <0.0, 1.0, 0.0>;default{    state_entry()    {        llSetPrimitiveParamsFast([PRIM_TYPE, PRIM_TYPE_SPHERE, PRIM_HOLE_DEFAULT, cut, hollow, twist, dimple]);    }}

I just need to get it to alternate 0.5 to 0.25 constantly every few seconds.

Link to comment
Share on other sites

There's no such function as llSetPrimitiveParamsFast.  

If you've got only the single prim, your choices are llSetPrimitiveParams([parameters]), which sleeps the script for 0.2 seconds, and llSetLinkPrimitiveParamsFast(LINK_THIS,[params]), which doesn't introduce a delay.

If you're simply switching between two degrees of hollowness, then I'd use this mechanism:

float fSolid = 0.0;float fHollow = 0.95;float fHowHollow;vector cut = <0.5, 1.0, 0.0>;vector twist = <0.0, 0.0, 0.0>;vector dimple = <0.0, 1.0, 0.0>;integer toggle;default{	state_entry()	{		llSetTimerEvent(2.0);		fHowHollow = fSolid; 		llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_TYPE, PRIM_TYPE_SPHERE,PRIM_HOLE_DEFAULT, cut, fHowHollow, twist, dimple]);	}	timer()	{		toggle=!toggle;//switch the value of toggle between 0 and 1 		if(toggle){ // if toggle == 1			fHowHollow = fHollow;		}		else{ //if toggle == 0			fHowHollow = fSolid;		}				llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_TYPE, PRIM_TYPE_SPHERE,PRIM_HOLE_DEFAULT, cut, fHowHollow, twist, dimple]);	}}

I wouldn't write it quite that way in one of my own scripts, but I'm trying to make the code easier to read.

If you want to have the hollow slowly shrink and grow, that's a bit more complex since you have to increase or decrease the hollowness by a small amount every time the timer event fires, but it's the same general principle.

  • Like 1
Link to comment
Share on other sites

Treat that part of the exercise as if you are turning a light switch on and off.  Create a global integer variable (functionally a boolean), and flip its value from TRUE to FALSE and back again on alternate triggerings of the timer event.  So, generically, if you were switching the prim's color, for example, you could flip it from red to green and back by using...

timer(){    llSetLinkPrimitiveParamsFast(link_number,[PRIM_COLOR,face,llList2Vector([<1,0,0>,<0,1,0>],(gON = !gON)), 1.0]);}

where gON is your integer switch.  If you have several parameters to toggle, then write gON = !gON as a separate line and just use its current value in the SLPPF statement as appropriate.

EDIT:   As Innula demonstrated while I was typing  ;)

Link to comment
Share on other sites

This is exactly what I was looking for! I didn't know toggle was a thing or I probably would have looked that up o.O I'll fiddle with this script for a bit, because I would like to try and do what you said and have a slow transition (if not then oh well). Thank you so much :D

 

EDIT: I have failed miserably in trying to add more value changes, but I have been able to change this from using Hollow to Dimple, which looks better for the design I am going for.

Link to comment
Share on other sites

Here's basically the sam script that Inulla posted, but with fewer lines:

vector cut = <0.5, 1.0, 0.0>;vector twist = <0.0, 0.0, 0.0>;vector dimple = <0.0, 1.0, 0.0>;list hollow = [0.0, 0.95];integer toggle;default{    state_entry()    {        llSetTimerEvent(2.0);         llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_TYPE, PRIM_TYPE_SPHERE,PRIM_HOLE_DEFAULT, cut, llList2Float(hollow,0), twist, dimple]);    }    timer()    {        llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_TYPE, PRIM_TYPE_SPHERE,PRIM_HOLE_DEFAULT, cut, llList2Float(hollow, toggle = !toggle), twist, dimple]);    }}

And this one uses steps to slowly change the hollow amount

vector cut = <0.5, 1.0, 0.0>;vector twist = <0.0, 0.0, 0.0>;vector dimple = <0.0, 1.0, 0.0>;float hstep;float solid = 0.0;float hollow = 0.95;integer toggle;integer steps = 5;default{    state_entry()    {        llSetTimerEvent(2.0);         llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_TYPE, PRIM_TYPE_SPHERE,PRIM_HOLE_DEFAULT, cut, solid, twist, dimple]);        hstep = (hollow-solid)/steps;    }    timer()    {        integer i;        float temphollow = llList2Float(llGetPrimitiveParams([PRIM_TYPE]),3);        do llSetPrimitiveParams([PRIM_TYPE, PRIM_TYPE_SPHERE,PRIM_HOLE_DEFAULT, cut,temphollow += hstep, twist, dimple]);//using llSetLinkPrimitiveParams here made it still too fast, unless you use more steps, or add a llSleep        while ((++i) < steps);        hstep = -hstep;    }}
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2936 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...