Can one use more than one timer event? Is there a better way?
|
Marianne McCann
Feted Inner Child
Join date: 23 Feb 2006
Posts: 7,145
|
11-03-2009 14:57
I'm still very much a n00b scripter, knowing just enough to be dangerous.
So I'm trying to make a light that flashes at night-time. During the day, it is off. I have two llSetTimeEvents that are being called for. One checks the sun position the other gives, in sexonds, how long the light should change from one state to the other.
Unfortunately, this does not work. It throws up a syntax error at the second "timer()"
Ayone have any thoughts on how to make this work? Is there maybe a better way to do this?
float Time = 30;
default { state_entry() { llSetTimerEvent(Time); llSetTimerEvent(2.0); } timer() { vector time = llGetSunDirection(); if (time.z > 0.0) { llSetPrimitiveParams([PRIM_GLOW, ALL_SIDES, 0.0]);llSetPrimitiveParams([PRIM_FULLBRIGHT, ALL_SIDES, FALSE]);
return; } else { timer() { if llSetPrimitiveParams([PRIM_GLOW, ALL_SIDES, 0.0]); else llSetPrimitiveParams([PRIM_GLOW, ALL_SIDES, 0.5]); } } }
}
_____________________
  "There's nothing objectionable nor illegal in having a child-like avatar in itself and we must assume innocence until proof of the contrary." - Lewis PR Linden "If you find children offensive, you're gonna have trouble in this world  " - Prospero Linden
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
11-03-2009 15:22
No, you can't have more than one timer event in the same state. In this case, I don't see why you need two timers, though. Try something like this .... integer ON = TRUE; default { state_entry() { llSetTimerEvent(2); }
timer() { vector Sun = llGetSunDirection(); if (Sun.z < 0) { llSetPrimitiveParams([PRIM_GLOW, ALL_SIDES, 0.5*ON]); ON = !ON; } } }
It checks the sun angle every two seconds and, if it's nighttime, turns the light on or off. That's what you wanted, right? ETA: Incidentally, glow is a pretty nasty feature. It shines through any 32 bit texture, so it can really annoy neighbors. I'd suggest using PRIM_FULLBRIGHT instead, in which case you write llSetPrimitiveParams([PRIM_FULLBRIGHT,ALL_SIDES,ON]). 
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
Marianne McCann
Feted Inner Child
Join date: 23 Feb 2006
Posts: 7,145
|
11-03-2009 15:39
From: Rolig Loon It checks the sun angle every two minutes and, if it's nighttime, turns the light on or off. That's what you wanted, right? If it were only that easy.  Actually, in night, I want it to "blink" on and off, like what you might see on an old-time Vegas marquee. Point taken on the glow!
_____________________
  "There's nothing objectionable nor illegal in having a child-like avatar in itself and we must assume innocence until proof of the contrary." - Lewis PR Linden "If you find children offensive, you're gonna have trouble in this world  " - Prospero Linden
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
11-03-2009 16:26
OK... But that's what this ought to do.... Ah.. I see that I wrote the script correctly but typed the word "minutes" where I meant "seconds." Hence, the confusion. It's been one of those days.....  Anyway..... My suggested script checks the timer every two SECONDS and then, if it's nighttime, flicks the light on or off. It really shouldn't matter what happens in the daytime. The timer still checks every two seconds, but nothing happens. Now, if you really don't like the idea of the timer clicking every two seconds in the daytime, make it click slower, like this .... integer ON = TRUE; default { state_entry() { llSetTimerEvent(2); //Every two seconds }
timer() { vector Sun = llGetSunDirection(); if (Sun.z < 0) { llSetTimerEvent(2); // Every two seconds llSetPrimitiveParams([PRIM_FULLBRIGHT, ALL_SIDES, ON]); ON = !ON; } else { llSetTimerEvent(120); // Every two minutes } } }
ETA: I just tested this in world. Works like a charm.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
|
11-03-2009 16:41
/me wrote up a script but the one Rolig did is a lot shorter. Jerk.  One thing I will add is that the "correct" way to do flashing is with an animated texture instead of with a timer. Have an image strip with frames that increase/decrease the transparency so that when you run it through llAnimateTexture, it has the effect of flashing. The timer way certainly works (and that's what my script did, too) but every time you update the prim, it's doing an object update - resending the prim params to every client nearby. It's also having to run the script every 2 seconds instead of every 2 minutes. It's not a huge thing but would get you bonafide "low lag!" bragging rights if this was for a new product you're doing. edit: and don't ask me how to do such an image strip - I have no idea! I'm sure Chosen or Chip or somebody like that would be willing to lend you a hand, though.
_____________________
Sick of sims locking up every time somebody TPs in? Vote for SVC-3895!!! - Go here: https://jira.secondlife.com/browse/SVC-3895- If you see "if you were logged in.." on the left, click it and log in - Click the "Vote for it" link on the left
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
11-03-2009 16:52
Yeah, you're right, Sindy. That's actually a good argument for making the modification I put in my second post. At least it reduces lag in the daytime. The idea of using an animated texture is nice, though, and it would drop lag even further. I ought to try that. 
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
|
11-03-2009 17:22
_____________________
Sick of sims locking up every time somebody TPs in? Vote for SVC-3895!!! - Go here: https://jira.secondlife.com/browse/SVC-3895- If you see "if you were logged in.." on the left, click it and log in - Click the "Vote for it" link on the left
|
Marianne McCann
Feted Inner Child
Join date: 23 Feb 2006
Posts: 7,145
|
11-03-2009 18:36
The above does work fab.
To give a better sense of what I'm doing, I have a complex sculpt that is serving as a "group" of light bulbs. The overall look provides more solidity than an animated texture, which I was not happy with the look of.
Is there any way to introduce it with glow in conjunction with the full bright? Understanding the issues with Glow, it simply does make the lights" appear far more "real" in context.
_____________________
  "There's nothing objectionable nor illegal in having a child-like avatar in itself and we must assume innocence until proof of the contrary." - Lewis PR Linden "If you find children offensive, you're gonna have trouble in this world  " - Prospero Linden
|
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
|
11-03-2009 18:48
I still think an animated texture has potential to look great. Then again, I haven't tried it and don't know how to make one so I guess I'll take your word for it.
Anway, to answer your question, I think you can add this to the very top of the script:
list gBlinkOn = [PRIM_GLOW, ALL_SIDES, 0.5, PRIM_FULLBRIGHT, ALL_SIDES, 1]; list gBlinkOff = [PRIM_GLOW, ALL_SIDES, 0.0, PRIM_FULLBRIGHT, ALL_SIDES, 0];
...then, in timer(), change this...
llSetPrimitiveParams([PRIM_FULLBRIGHT, ALL_SIDES, ON]);
...to be..
if (ON) { llSetPrimitiveParams (gBlinkOn); } else { llSetPrimitiveParams (gBlinkOff); }
/me thinks that'll do it. Doing both glow and fullbright in one call will save you an object update..
_____________________
Sick of sims locking up every time somebody TPs in? Vote for SVC-3895!!! - Go here: https://jira.secondlife.com/browse/SVC-3895- If you see "if you were logged in.." on the left, click it and log in - Click the "Vote for it" link on the left
|
Rime Wirsing
Color me gone
Join date: 31 Dec 2008
Posts: 345
|
11-03-2009 19:36
I'll show you mine if you show me yours  Three prims, couple of textures and a scrolling texture script...  Rough first stab. Rime
|
Marianne McCann
Feted Inner Child
Join date: 23 Feb 2006
Posts: 7,145
|
11-03-2009 19:42
Thanks all. I think I've got it. I may do some more fiddling, the the beast is in Bay City - Imaginario,50, 250.
_____________________
  "There's nothing objectionable nor illegal in having a child-like avatar in itself and we must assume innocence until proof of the contrary." - Lewis PR Linden "If you find children offensive, you're gonna have trouble in this world  " - Prospero Linden
|
Rime Wirsing
Color me gone
Join date: 31 Dec 2008
Posts: 345
|
11-03-2009 19:55
Ohhhhh,, the sign on the post outside the toy store? Did I imagine a different kind of sign Oh well - was fun and might fiddle with the idea some more. Rime
|
Marianne McCann
Feted Inner Child
Join date: 23 Feb 2006
Posts: 7,145
|
11-03-2009 21:12
From: Rime Wirsing Ohhhhh,, the sign on the post outside the toy store? Did I imagine a different kind of sign Oh well - was fun and might fiddle with the idea some more. Rime The very same 
_____________________
  "There's nothing objectionable nor illegal in having a child-like avatar in itself and we must assume innocence until proof of the contrary." - Lewis PR Linden "If you find children offensive, you're gonna have trouble in this world  " - Prospero Linden
|
Rime Wirsing
Color me gone
Join date: 31 Dec 2008
Posts: 345
|
11-04-2009 06:16
OK - with a better idea of what was required I decided to have another shot at producing the desired effect using textures. Purely an exercise on my part but offered here for consideration. Came up with two versions. The first version uses three prims: Base and two light bulb layers. A script simply toggles fullbright on each light bulb layer. The script sleep introduced by the two prim parameter changes results in less than perfect timing. Version two uses a single light bulb prim and the script replaces the face texture, toggling between two textures that have alternate 'lit' bulbs. For the exercise I used a single prim and let alpha define the sign shape. This would work for a wall sign but a freestanding sign, like Mariannes street sign, each section would need to have its own textures. So here's what the two methods look like side by side.  Rime
|
Rime Wirsing
Color me gone
Join date: 31 Dec 2008
Posts: 345
|
11-04-2009 11:49
Oh yeah! Now we are talking - animated textures using a multi-frame image is definitely the way to go. Created a four frame image with alternate bulbs lit states interleaved with an all bulbs dim state. Animated this using llSetTextureAnim. Result...  ... cool  Rime
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
11-04-2009 11:53
WooHoo!! That IS cool. WTG, Rime. 
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|