Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Flickering Candlelight

Rowan Carroll
She's So Unusual Shoes
Join date: 4 Mar 2006
Posts: 94
05-18-2007 02:19
I've been searching the forums for a working flickering candle light script. I know I've seen them.

Not particle based, but using the "light" function of a prim. I can't code worth a darn, though I did get a prim once to say "Hello, Avatar!"

Any ideas? Is it even possible?
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
05-18-2007 03:04
From: Rowan Carroll
I've been searching the forums for a working flickering candle light script. I know I've seen them.

Not particle based, but using the "light" function of a prim. I can't code worth a darn, though I did get a prim once to say "Hello, Avatar!"

Any ideas? Is it even possible?


You would need to alter the light parameters randomly on a random interval timer.

CODE



float intensity = 1.0;
float radius = 10.0;
float falloff = 0.75;

vector on = <1.0,1.0,0.0>; // Yellow ish
vector off = <0.0,0.0,0.0>;

integer Flag = FALSE;

LightOn()
{

float val = llFrand(0.8); // 80 % variation - chaneg as required.
llSetPrimitiveParams([
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_COLOR, 0, on, falloff,
PRIM_POINT_LIGHT, TRUE, on, (intensity - val), (radius - (val * 10.)), falloff
]);
llSetTimerEvent(llFrand(0.5));

}

LightOff()
{
llSetColor(off,ALL_SIDES);
llSetPrimitiveParams([
PRIM_FULLBRIGHT, ALL_SIDES, FALSE,
PRIM_COLOR, 0, on, falloff,
PRIM_POINT_LIGHT, FALSE, off, intensity, radius, falloff
]);
llSetTimerEvent(0.);

}

default
{
state_entry()
{
Flag = FALSE;
LightOff();
}

touch_start(integer total_number)
{
Flag = ! Flag;
if(Flag)
LightOn();
else
LightOff();
}
}
_____________________
I'm back......
Milambus Oh
Registered User
Join date: 6 Apr 2007
Posts: 224
05-18-2007 09:43
In my experience the Light setting really isn't enough to give the visual impression of a flickering candle. So hopefully you are combining it with an animated texture or something.
Ee Maculate
Owner of Fourmile Castle
Join date: 11 Jan 2007
Posts: 919
05-18-2007 09:53
From: Milambus Oh
In my experience the Light setting really isn't enough to give the visual impression of a flickering candle. So hopefully you are combining it with an animated texture or something.


Or a flexi-prim?
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
05-18-2007 10:10
From: Newgate Ludd
You would need to alter the light parameters randomly on a random interval timer.


You left out your timer() event, "Newgy" *chuckles*. ;)

CODE



float intensity = 1.0;
float radius = 10.0;
float falloff = 0.75;

vector on = <1.0,1.0,0.0>; // Yellow ish
vector off = <0.0,0.0,0.0>;

integer Flag = FALSE;

LightOn()
{

float val = llFrand(0.8); // 80 % variation - chaneg as required.
llSetPrimitiveParams([
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_COLOR, 0, on, falloff,
PRIM_POINT_LIGHT, TRUE, on, (intensity - val), (radius - (val * 10.)), falloff
]);
llSetTimerEvent(llFrand(0.5));

}

LightOff()
{
llSetColor(off,ALL_SIDES);
llSetPrimitiveParams([
PRIM_FULLBRIGHT, ALL_SIDES, FALSE,
PRIM_COLOR, 0, on, falloff,
PRIM_POINT_LIGHT, FALSE, off, intensity, radius, falloff
]);
llSetTimerEvent(0.);

}

default
{
state_entry()
{
Flag = FALSE;
LightOff();
}

touch_start(integer total_number)
{
Flag = ! Flag;
if(Flag)
LightOn();
else
LightOff();
}
timer()
{
LightOn();
}
}
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
Rofl
05-18-2007 11:47
Yep I did, all I can say is D'OH!
_____________________
I'm back......
Fiona Branagh
... or her equivalent.
Join date: 1 Feb 2007
Posts: 156
05-18-2007 12:18
I always make a 'light ball' to surround the actual flame. It takes the place of the aura we usually see around the candleflame in real life, and helps to get that flicker.

I make the ball, I place it around the flame, I make it partially transparent and a yellow-white color, and make it emanate light.

Then as shown above in code form, manipulate the transparency and light levels at random intervals.

Seems to work just fine.
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
05-10-2008 21:42
well i know this thread is about a year old, but i thought i'd give it a try. i tried the script, it works great, except, when i touch it to turn it off, it still flickers, all i changed was the color of the on light, did sl change something in the lsl that's causing that, or does something need to be fixed
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
05-10-2008 21:47
From: Ruthven Willenov
well i know this thread is about a year old, but i thought i'd give it a try. i tried the script, it works great, except, when i touch it to turn it off, it still flickers, all i changed was the color of the on light, did sl change something in the lsl that's causing that, or does something need to be fixed

nevermind that, i tried it again, it works, but you gotta touch it at the right time, either during or in between timers, very strange, but that's SL for ya lol
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
05-11-2008 02:02
You need to be careful with fast timers. Firstly I'd switch the timer off sooner rather than later in the LightOff() function (llSetPrimitiveParams has a 0.2 second delay and can itself cause timing problems):

From: code

LightOff()
{
llSetTimerEvent(0.); // kill the timer

llSetColor(off,ALL_SIDES);
llSetPrimitiveParams([
PRIM_FULLBRIGHT, ALL_SIDES, FALSE,
PRIM_COLOR, 0, on, falloff,
PRIM_POINT_LIGHT, FALSE, off, intensity, radius, falloff
]);
}

...and to be really sure the LightOn() function could acknowledge the setting of 'Flag':

From: code

LightOn()
{
if(Flag)
{
float val = llFrand(0.8); // 80 % variation - chaneg as required.
llSetPrimitiveParams([
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_COLOR, 0, on, falloff,
PRIM_POINT_LIGHT, TRUE, on, (intensity - val), (radius - (val * 10.)), falloff
]);
llSetTimerEvent(llFrand(0.5));
}
}

This should ensure that LightOn() doesn't sneak in under the wire in the time it takes the script to fully respond to the touch event.
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
05-24-2008 21:00
well here's this one i made using a prim color changing script, i just modified it a bit to use it for light instead of the prim color. any way i could add a touch start/stop in it? can't figure that out, i had a touch start, but it only cycled once

From: someone

vector FIRST_COLOR = <1.00000, 0.50196, 0.00000>;
vector SECOND_COLOR = <1.00000, 0.52941, 0.05490>;
vector THIRD_COLOR = <1.00000, 0.63137, 0.25882>;

default {
state_entry() {
//
// all states will hear this timer until one of them
// stops it using llSetTimerEvent( 0.0 )
//
llSetTimerEvent(llFrand(0.5) + 0.25);
//
// start the color cycle
//
state first_color;
}
}

state first_color {
state_entry() {
llSetPrimitiveParams([PRIM_FULLBRIGHT,ALL_SIDES,FALSE,PRIM_POINT_LIGHT,TRUE,FIRST_COLOR,1.0,5.0,0.6]);
}

timer() {
state second_color;
}
}

state second_color {
state_entry() {
llSetPrimitiveParams([PRIM_FULLBRIGHT,ALL_SIDES,FALSE,PRIM_POINT_LIGHT,TRUE,SECOND_COLOR,0.9,5.0,0.6]);
}

timer() {
state third_color;
}
}

state third_color {
state_entry() {
llSetPrimitiveParams([PRIM_FULLBRIGHT,ALL_SIDES,FALSE,PRIM_POINT_LIGHT,TRUE,THIRD_COLOR,0.7,5.0,0.6]);
}

timer() {
state first_color;
}
}
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
09-09-2008 19:49
i was playing around with some flickering scripts again today and figured out a pretty good solution. i have one script that flickers continuously, no switch in that script, and then i have a seperate script switch in that prim that sets the flicker script running/not running using the llSetScriptStatus function. only way i could figure out how to get around that 0.2 second sleep the llSetPrimitiveParams creates
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Paulo Dielli
Symfurny Furniture
Join date: 19 Jan 2007
Posts: 780
09-09-2008 19:57
I miss Newgate Ludd. Whatever happened to him? :(
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
09-10-2008 12:34
From: Paulo Dielli
I miss Newgate Ludd. Whatever happened to him? :(

:p not sure, but what's wrong with the rest of us?
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369