help with setting up a timed event
|
|
Cheewha Palen
Registered User
Join date: 27 Nov 2007
Posts: 78
|
07-20-2008 14:29
Hello I am trying to make a box "materialize" out of thin air from an alpha set at zero to an alpha set at one. But i want it to take its time doing this like maybe five seconds total. so in my script I have tried setting "setalpha" repeated from zero to 0.25, 0.5, 0.75, and finally one. This works but still a bit too fast. while looking in the wiki at set alpha i saw an event timer and tried adding that also but I dont think I did it correctly. So here is the script I have so far.. you will also notice a setpos in there what I am doing is making the box rise up out of ground and be visible and then go invisible and sink back into ground outa the way. ok the script:
integer close_on_rez = TRUE;
open(string door) { llSetPos(llGetPos()+<0,0,3.1>); llSetLinkAlpha(LINK_SET, 0.25, ALL_SIDES); llSetTimerEvent(5.0); llSetLinkAlpha(LINK_SET, 0.5, ALL_SIDES); llSetTimerEvent(5.0); llSetLinkAlpha(LINK_SET, 0.75, ALL_SIDES); llSetTimerEvent(5.0); llSetLinkAlpha(LINK_SET, 1.0, ALL_SIDES);
}
close(string door) { llSetLinkAlpha(LINK_SET, 0.0, ALL_SIDES); llSetPos(llGetPos()-<0,0,3.1>); }
default { state_entry() { if (close_on_rez) { state closed; } else { state opened; } } on_rez(integer rez) { llResetScript(); } }
state opened { state_entry() { open("left"); } on_rez(integer rez) { llResetScript(); } touch_start(integer n) { state closed; } }
state closed { state_entry() { close("left"); } on_rez(integer rez) { llResetScript(); } touch_start(integer n) { state opened; } }
So ok ultimately what i would like in a perfect world is for the box to detect the owner via proximinty (its by touch for now) rise become visible slowly and after a set time return to invisible hidden in ground state. but any help on just getting the texture to slowly alpha would be much help indeed!
|
|
Nika Talaj
now you see her ...
Join date: 2 Jan 2007
Posts: 5,449
|
07-20-2008 14:53
Hi Cheewa! Changing the alpha slowly via a timed event is quite possible ... I have a picture frame script that does cross-fades in exactly that way. One thing I notice in your script is that you set the timer event, but I don't see you ever process the event (after 5 seconds goes by). For every state in which the timer could go off, you can put a routine to do something every 5 seconds. Here's one that removes the listen for a dialog box after a timer expires: timer() { menu_handle = remove_listen(menu_handle); llSay(0,"Menu buttons timed out."); }
.
|
|
Cheewha Palen
Registered User
Join date: 27 Nov 2007
Posts: 78
|
07-20-2008 15:43
hi nika thanks for responding, Im gonna have to read up on timers cozI am not sure how to apply that...lol
|
|
Cheewha Palen
Registered User
Join date: 27 Nov 2007
Posts: 78
|
07-20-2008 19:54
Hi sorry I am struggling can any one post any good examples of setting up a timer event?
|
|
DrDoug Pennell
e-mail is for old people
Join date: 13 Mar 2007
Posts: 112
|
07-20-2008 20:13
From: Cheewha Palen Hello
I am trying to make a box "materialize" out of thin air from an alpha set at zero to an alpha set at one. But i want it to take its time doing this like maybe five seconds total. Why not something simple like this? while(alpha_num<=1.0) { llSetAlpha(alpha_num, ALL_SIDES); alpha_num=alpha_num+.001; } It makes the object appear over about 4-5 seconds. Doug
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
07-20-2008 20:28
Or... float FADE_PERIOD = 5.0;
float fadeStartTime = 0.0; float calcAlpha(float time) { float t = (time-fadeStartTime)/FADE_PERIOD; if (t <= 0.0) { return 0.0; } else if (t >= 1.0) { return 1.0; } else { return t; } }
|
|
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
|
07-20-2008 21:21
Well, since everyone's offering different ways, and no one is actually answering your question as asked (how to use the timer event), here it is... float inc;
default { state_entry() { llSetTimerEvent (0.25); }
timer() { inc += 0.05; llSetAlpha (inc, ALL_SIDES); if (inc == 1.0) { llSetTimerEvent (0.0); } } }
the timer event is 'set up' in the state entry, then, ever 0.25 seconds (1/4 second), the timer event 'fires', and the code in the timer event is executed, where the alpha is incremented by 0.05, therefore, it will take twenty times to get from an alpha of 0.0 to 1.0. 20 divided by 0.25 = 5, so it will take 5 seconds for the effect to occur, at which time the if conditional is now true, and the timer event is 'shut off' by the llSetTimerEvent (0.0); http://www.secondscripter.com
_____________________
My tutes http://www.youtube.com/johanlaurasia
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
07-21-2008 00:29
From: Johan Laurasia Well, since everyone's offering different ways, and no one is actually answering your question as asked (how to use the timer event)... Oh. True. Here's how you might use a function like the one I posted above to implement this kind of thing. Note that the very simple change in behavior here I implemented with a boolean (integer) variable rather than multiple states. Also the alpha as a function of time (at least I think) makes a little more intuitive sense than counting steps. float TIMER_PERIOD = 0.1; float FADE_PERIOD = 5.0;
integer open = FALSE; float fadeEndTime = 0.0;
float calcOpeningAlpha(float time) { float t = (fadeEndTime-time)/FADE_PERIOD; if (t <= 0.0) { return 0.0; } else if (t >= 1.0) { return 1.0; } else { return t; } }
default { state_entry() { if (open) { llSetLinkAlpha(LINK_SET, 1.0, ALL_SIDES); } else { llSetLinkAlpha(LINK_SET, 0.0, ALL_SIDES); } }
on_rez(integer startParam) { // If really desired llResetScript(); }
touch_start(integer nDetected) { llSetTimerEvent(0.0);
open = !open; if (!open) { llSetLinkAlpha(LINK_SET, 0.0, ALL_SIDES); } else { fadeEndTime = llGetTime()+FADE_PERIOD; llSetTimerEvent(TIMER_PERIOD); } }
timer() { float time = llGetTime(); float alpha = calcOpeningAlpha(time);
llSetLinkAlpha(LINK_SET, alpha, ALL_SIDES);
if (time > fadeEndTime) { llSetTimerEvent(0.0); } } }
|
|
Cheewha Palen
Registered User
Join date: 27 Nov 2007
Posts: 78
|
(insane face) make the sound stop
07-21-2008 19:15
I would like to thank everyone for posting. This is what I love about the script forums lots of people willing to offer help. I have been wrecking my brain all day on scripts...looking in wiki looking at examples in my inventory. I still haven't figured out the "materializing" part yet--everyones examples work just I had trouble making them work in my original script--thats on me. Soooo I decided to wait on that and work on some of the other functions I wanted to happen... And with moderate success! I am trying to have a box at a teleport location that is defaulted to alpha zero (and maybe phantom to but thats not as important to me at this point) and when I teleport to that location the box detects me and changes alpha to one so it is seen. Okay so far I have had success with this. I also want it to play a sound two times. Once when I first arrive (again success) and once more once I am out of detect range and the box alphas back to zero. And that happens except once I am away from the box the sound loops over and over and never stops until I come back to detection range at which time it plays like it is supposed to and then stops. This last part has me stuck! So all that....my question is: How do I get the sound to stop? I try using llStopSound() in the default state,If i put it at the endthe sound never plays...so I coould use a good pointing in the right direction please? Here is the code I have: integer Nearby = 0;
default { state_entry() { llSetLinkAlpha(LINK_SET, 0.0, ALL_SIDES); llStopSound(); llSetTimerEvent(5.0); }
timer() { llSensor("",NULL_KEY,AGENT,5,PI); }
sensor(integer num_detected) { if (Nearby == 0) {
llSetLinkAlpha(LINK_SET, 1.0, ALL_SIDES); llPlaySound("mysound", 10.0); Nearby = 1; } }
no_sensor() { Nearby = 0; llPlaySound("mysound", 10); llSetLinkAlpha(LINK_SET, 0.0, ALL_SIDES); state default; } }
|