Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

On/Off Flame script?

Kattyn Razor
Registered User
Join date: 27 Sep 2007
Posts: 11
04-26-2008 15:11
Hi all. I'm in the process of making some candles and am having trouble locating a script that will allow me to turn the flame and and off by touch. Any idea where I can find such a script?

Thanks!
Nectere Niven
Gadget Junky
Join date: 12 Jan 2007
Posts: 211
04-26-2008 15:57
What I assume you want is a switch to turn on AND off and back to on. SO you need a touch event like the example below. As well as setting the alpha, you can add texture animation and so forth, whatever you want. This is a per prim deal, now you could put this in a root prim and have it tell the child prims to listen on a certain channel and do stuff, that is slightly different. I think if you look in the wiki there is a lsl fire example that includes a touch event I am not sure.


CODE


default
{
state_entry()
{

state on;//we are going to start with the on state, but you could easily change it to off
}
}


state on //here we are declaring what exactly is the state of "on"
{
state_entry()
{
llSetAlpha (1.0, ALL_SIDES); //OR do what ever you want here, list out your params however you want. Here I have said for on, be visible on all sides of the prim.

}
touch_start(integer num_touches)
{
state off; //goto the next state on touch
}
}
state off //here we are declaring what is the "off" state
{
state_entry()
{
llSetAlpha(0.0, ALL_SIDES);//OR do what ever you want here, list out your params however you want, here I have said for off, be invisible on all sides of the prim.

}

touch_start(integer num_touches)
{
state on; //goto the next state on touch which in this case is back to the beginning, this makes it a on off switch, but you could declare additional states if you wanted, this is touch once, go to on, touch again go to off, touch again go to on and so forth.
}

}


That said, I have no idea if you are using prims with texture animation or particles...
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
04-26-2008 17:38
Bare bones integer switch:

CODE
integer on = 1;

default {
touch_start(integer n) {
if (on)
llSetAlpha(1.0, ALL_SIDES);
else
llSetAlpha(0.0, ALL_SIDES);
on = !on;
}
}
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
04-27-2008 01:52
Here's a cute little flame effect. I wish I could take all the credit for it but the particle part isn't mine... only I can't remember where I got it from. :o (I believe it might be by Oz Spade). The on/off is pretty standard stuff although I'm not sure I wrote that part either!

Anywho's here you go...

CODE

integer OnOff;

flameParticles()
{
llParticleSystem([
PSYS_PART_MAX_AGE, 0.4,
PSYS_PART_START_COLOR, <1, 0.5, 0>,
PSYS_PART_END_COLOR, <1, 1, 0>,
PSYS_PART_START_SCALE, <0.06, 0.08, 0.06>,
PSYS_PART_END_SCALE, <0.04, 0.08, 0.04>,
PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_ANGLE_CONE_EMPTY,
PSYS_SRC_BURST_RATE,0.01,
PSYS_SRC_ACCEL, <0, 0, 0.7>,
PSYS_SRC_BURST_PART_COUNT, 100,
PSYS_SRC_BURST_RADIUS, 0.001,
PSYS_SRC_BURST_SPEED_MIN, 0.1,
PSYS_SRC_BURST_SPEED_MAX, 0.1,
// PSYS_SRC_TARGET_KEY, "",
PSYS_SRC_INNERANGLE, 0.9,
PSYS_SRC_OUTERANGLE, 0.08,
PSYS_SRC_OMEGA, <0, 0, 0>,
PSYS_SRC_MAX_AGE, 0.0,
PSYS_SRC_TEXTURE, "",
PSYS_PART_START_ALPHA, 1.0,
PSYS_PART_END_ALPHA, 0.0,
PSYS_PART_FLAGS, ( 0
| PSYS_PART_INTERP_COLOR_MASK
| PSYS_PART_INTERP_SCALE_MASK
| PSYS_PART_EMISSIVE_MASK
// | PSYS_PART_FOLLOW_VELOCITY_MASK
// | PSYS_PART_WIND_MASK
// | PSYS_PART_BOUNCE_MASK
| PSYS_PART_FOLLOW_SRC_MASK
// | PSYS_PART_TARGET_POS_MASK
// | PSYS_PART_TARGET_LINEAR_MASK
)]);
}

default
{
state_entry()
{
OnOff = TRUE;
flameParticles();
llSetPrimitiveParams([
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_COLOR, 0, <1.0, 1.0, 0.0>, 0.75,
PRIM_POINT_LIGHT, TRUE, <1.0, 1.0, 0.0>, 1.0, 10.0, 0.75
]);
}

touch_start(integer total_number)
{
if(OnOff = !OnOff)
{
flameParticles();
llSetPrimitiveParams([
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_COLOR, 0, <1.0, 1.0, 0.0>, 0.75,
PRIM_POINT_LIGHT, TRUE, <1.0, 1.0, 0.0>, 1.0, 10.0, 0.75
]);
}
else
{
llSetPrimitiveParams([
PRIM_FULLBRIGHT, ALL_SIDES, FALSE,
PRIM_COLOR, 0, <0.0, 0.0, 0.0>, 0.75,
PRIM_POINT_LIGHT, FALSE, <0.0, 0.0, 0.0>, 1.0, 10.0, 0.75
]);
llParticleSystem([]);
}
}
}
Morris Mertel
Registered User
Join date: 2 Mar 2007
Posts: 32
04-28-2008 04:16
WOW nice flame Pale!

Does anybody know how I can use this in a chandelier?
To turn several candles turn on and off by one touch (and just one candle with the, don't know how it's called, full bright point light effect, otherwise the whole room becomes an inferno).
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
04-28-2008 08:34
hehe... I didn't make the flame particles. I'm useless with particles. However, I'm pretty good at doing controls for stuff. :D

This will take a little care in how you set up your chandelier.

The script needs to go in the Parent Prim, plus the wick of each candle (where the flame will appear).

If the description on the wick is just 'Wick' then it will only do the flame particle. If the description is 'Wick Bright' it will do both particles and the lighting.

So, one script, but it behaves according to the prim it is in (parent or child) and according to the description of the prim ('Wick' or 'Wick Bright'). With particles involved you're kind of stuck with many scripts but at least this way all the scripts are the same. :)

CODE

integer OnOff;

flameParticles()
{
llParticleSystem([
PSYS_PART_MAX_AGE, 0.4,
PSYS_PART_START_COLOR, <1, 0.5, 0>,
PSYS_PART_END_COLOR, <1, 1, 0>,
PSYS_PART_START_SCALE, <0.06, 0.08, 0.06>,
PSYS_PART_END_SCALE, <0.04, 0.08, 0.04>,
PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_ANGLE_CONE_EMPTY,
PSYS_SRC_BURST_RATE,0.01,
PSYS_SRC_ACCEL, <0, 0, 0.7>,
PSYS_SRC_BURST_PART_COUNT, 100,
PSYS_SRC_BURST_RADIUS, 0.001,
PSYS_SRC_BURST_SPEED_MIN, 0.1,
PSYS_SRC_BURST_SPEED_MAX, 0.1,
// PSYS_SRC_TARGET_KEY, "",
PSYS_SRC_INNERANGLE, 0.9,
PSYS_SRC_OUTERANGLE, 0.08,
PSYS_SRC_OMEGA, <0, 0, 0>,
PSYS_SRC_MAX_AGE, 0.0,
PSYS_SRC_TEXTURE, "",
PSYS_PART_START_ALPHA, 1.0,
PSYS_PART_END_ALPHA, 0.0,
PSYS_PART_FLAGS, ( 0
| PSYS_PART_INTERP_COLOR_MASK
| PSYS_PART_INTERP_SCALE_MASK
| PSYS_PART_EMISSIVE_MASK
// | PSYS_PART_FOLLOW_VELOCITY_MASK
// | PSYS_PART_WIND_MASK
// | PSYS_PART_BOUNCE_MASK
| PSYS_PART_FOLLOW_SRC_MASK
// | PSYS_PART_TARGET_POS_MASK
// | PSYS_PART_TARGET_LINEAR_MASK
)]);
}

default
{
state_entry()
{
if (llGetLinkNumber() <= 1) // Parent Prim
{
OnOff = TRUE;
llMessageLinked(LINK_SET, OnOff, "", NULL_KEY);
}
else llPassTouches(TRUE); // Child Prims
}

touch_start(integer total_number)
{
if (llGetLinkNumber() <= 1) llMessageLinked(LINK_SET, OnOff = !OnOff, "", NULL_KEY);
}

link_message(integer sender_num, integer num, string str, key id)
{
if (llGetSubString(llGetObjectDesc(), 0, 3) == "Wick")
{
if(num)
{
flameParticles();
if (llGetObjectDesc() == "Wick Bright")
llSetPrimitiveParams([
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_COLOR, 0, <1.0, 1.0, 0.0>, 0.75,
PRIM_POINT_LIGHT, TRUE, <1.0, 1.0, 0.0>, 1.0, 10.0, 0.75
]);
}
else
{
//if (llGetObjectDesc() == "Wick Bright")
//I found it better to have all 'wicks' turn the lighting off because if you use
//shift-copy it's too easy to end up with lighting where you didn't mean to.
llSetPrimitiveParams([
PRIM_FULLBRIGHT, ALL_SIDES, FALSE,
PRIM_COLOR, 0, <0.0, 0.0, 0.0>, 0.75,
PRIM_POINT_LIGHT, FALSE, <0.0, 0.0, 0.0>, 1.0, 10.0, 0.75
]);
llParticleSystem([]);
}
}
}
}
Morris Mertel
Registered User
Join date: 2 Mar 2007
Posts: 32
04-28-2008 10:19
Thanks so much Pale. The wicks i called Wick and the rootprim i called Wick Bright in each of this prim i put this script and tataaaa...... Absolutely nothing happen here :) ...
No errors but no flame either... Hmmm maybe i'm just too stupid :) wheeee
Keira Wells
Blender Sculptor
Join date: 16 Mar 2008
Posts: 2,371
04-28-2008 10:22
From: Morris Mertel
Thanks so much Pale. The wicks i called Wick and the rootprim i called Wick Bright in each of this prim i put this script and tataaaa...... Absolutely nothing happen here :) ...
No errors but no flame either... Hmmm maybe i'm just too stupid :) wheeee

The name of the prim doesn't have to be Wick or Wick Bright, I don't think, butt he description does, just below the name field in the edit menu.

If I misunderstood you, then sowwy ^_^
_____________________
Tutorials for Sculpties using Blender!
Http://www.youtube.com/user/BlenderSL
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
04-28-2008 10:28
Did you use the prim's Name or Description field?

llGetObjectDesc() will get the description, which is what I've used.

llGetObjectName() will get the name but if I used that you might end up with a chandelier called 'Wick Bright'. :D

[Kiera got there before me! :)]
Morris Mertel
Registered User
Join date: 2 Mar 2007
Posts: 32
04-28-2008 10:56
Aaaaah u see, i'm that stupid lol! Big thaaaaaaaaaanks, u're my hero (both) !!!
I'm happy lol
And guess what? It's working!!! Whohooooooooooo (do i sound like a sissy now?)
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
05-10-2008 20:58
It doesn't necessarily need the root prim's description to be wick bright it can be a child prim. say you have a candelabra, normally the root is the stand. which prim do you want to light up? the stand or the middle flame? ;-) just thought i'd point that out. also if you have a large fixture (up to 30m wide) you can tone down the light radius (so it's not too intense lol) and "describe" multiple prims with the Wick Bright so that the light evens out across the whole fixture
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
05-11-2008 02:11
However, you must have a copy of the script in the root prim to properly pick up the touch events - its description doesn't need to be either "Wick" or "Wick Bright" if the flame particle isn't appropriate on the root prim. Anything in the script conditioned by: llGetLinkNumber() <= 1 will only apply in the root prim.

Otherwise, as Ruthven says, the descriptions "Wick" and "Wick Bright" can be used on any of the prims in the link set as desired.
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
05-13-2008 16:00
thanks so much for the script. now my problem is, i changed the particles around to use it on a stove. works fine, except i want to be able to control each flame seperately. i tried putting "knobs" and changing the LINK_SET in the link messages to the appropriate link#, doesn't work. the touch event comes on blah blah blah, but the flame isn't turned off or on in the corresponding link. and like you said before about the script being in the root, i have it there of course, and if i click the root (the "shell" of the stove) all the flames go on/off
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
05-14-2008 12:47
Okay, having separate prims control each other in a link set is very much NOT a root prim effect. In fact, in this case, I recommend that you keep a clean root prim. So, once again using the same code in all scripts...

With this script you need to 'group' prims with descriptions like: 'Knob 1' and 'Fire 1', or 'Knob 2' and 'Fire Bright 2'

Clicking on one of the prims in the group will toggle the particle effect on the Fire/Fire Bright prim(s) - so clicking either the 'knob' control, or the 'burner' will switch the particles on and off. The number is important as it is this that groups the prims together. And, yes, you can have many 'burners' and/or 'controls' in the same group.

In this case the 'Fire Bright' thing is probably redundant but it does illustrate how using the prim's description can communicate all sorts of different behaviour to the script - think of it as Custom Attributes for the prim.

CODE

integer OnOff;

flameParticles()
{
llParticleSystem([
PSYS_PART_MAX_AGE, 0.4,
PSYS_PART_START_COLOR, <1, 0.5, 0>,
PSYS_PART_END_COLOR, <1, 1, 0>,
PSYS_PART_START_SCALE, <0.06, 0.08, 0.06>,
PSYS_PART_END_SCALE, <0.04, 0.08, 0.04>,
PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_ANGLE_CONE_EMPTY,
PSYS_SRC_BURST_RATE,0.01,
PSYS_SRC_ACCEL, <0, 0, 0.7>,
PSYS_SRC_BURST_PART_COUNT, 100,
PSYS_SRC_BURST_RADIUS, 0.001,
PSYS_SRC_BURST_SPEED_MIN, 0.1,
PSYS_SRC_BURST_SPEED_MAX, 0.1,
// PSYS_SRC_TARGET_KEY, "",
PSYS_SRC_INNERANGLE, 0.9,
PSYS_SRC_OUTERANGLE, 0.08,
PSYS_SRC_OMEGA, <0, 0, 0>,
PSYS_SRC_MAX_AGE, 0.0,
PSYS_SRC_TEXTURE, "",
PSYS_PART_START_ALPHA, 1.0,
PSYS_PART_END_ALPHA, 0.0,
PSYS_PART_FLAGS, ( 0
| PSYS_PART_INTERP_COLOR_MASK
| PSYS_PART_INTERP_SCALE_MASK
| PSYS_PART_EMISSIVE_MASK
// | PSYS_PART_FOLLOW_VELOCITY_MASK
// | PSYS_PART_WIND_MASK
// | PSYS_PART_BOUNCE_MASK
| PSYS_PART_FOLLOW_SRC_MASK
// | PSYS_PART_TARGET_POS_MASK
// | PSYS_PART_TARGET_LINEAR_MASK
)]);
}

default
{
touch_start(integer total_number)
{
integer iTemp = !OnOff;
llMessageLinked(LINK_SET, iTemp, llGetSubString(llGetObjectDesc(), -1, -1), NULL_KEY);
}

link_message(integer sender_num, integer num, string str, key id)
{
if (llGetSubString(llGetObjectDesc(), -1, -1) == str) // is this my group?
{
if (llGetSubString(llGetObjectDesc(), 0, 3) == "Fire") // am I a burner?
{
if(num)
{
flameParticles();
if (llGetSubString(llGetObjectDesc(), 0, 10) == "Fire Bright")
llSetPrimitiveParams([
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_POINT_LIGHT, TRUE, <1.0, 1.0, 0.0>, 0.5, 0.25, 0.75
]);
}
else
{
llSetPrimitiveParams([
PRIM_FULLBRIGHT, ALL_SIDES, FALSE,
PRIM_POINT_LIGHT, FALSE, <0.0, 0.0, 0.0>, 1.0, 10.0, 0.75
]);
llParticleSystem([]);
}
}
OnOff = !OnOff; // flip the On/Off state for all prims in this group
}
}
}


One caveat. Being able to write this script does not imply I know anything about cooking. ;)
Very Keynes
LSL is a Virus
Join date: 6 May 2006
Posts: 484
05-14-2008 15:59
From: Pale Spectre
One caveat. Being able to write this script does not imply I know anything about cooking. ;)


Thanks for the disclamer Pale, I tried your script and it burnt my Cilliconcarne :)
Dekka Raymaker
thinking very hard
Join date: 4 Feb 2007
Posts: 3,898
05-14-2008 18:25
From: Very Keynes
Thanks for the disclamer Pale, I tried your script and it burnt my Cilliconcarne :)

OMG you should never cook naked!
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
05-14-2008 22:42
thanks pale! i've just gotten into using link messages so i don't fully understand how it works. but anyways, here's the script rewritten with the flames i use for the stove (blue rings) works perfectly, thanks again!

From: someone

integer OnOff;

flameParticles()
{
llParticleSystem( [
PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_ANGLE,
PSYS_SRC_BURST_PART_COUNT,1000,
PSYS_SRC_BURST_RATE,0.001,
PSYS_PART_MAX_AGE,5.0,
PSYS_SRC_BURST_RADIUS, 0.15,
PSYS_SRC_OUTERANGLE, PI,
PSYS_SRC_BURST_SPEED_MIN,0.001,
PSYS_SRC_BURST_SPEED_MAX, 0.01,
PSYS_SRC_ACCEL, < 0, 0, 0.0 >,
PSYS_PART_START_SCALE, < 0.04, 0.04, 0.04 >,
PSYS_PART_END_SCALE, < 0.01, 0.075, 0.05 >,
PSYS_PART_START_COLOR,< 0.0, 0.0, 1 >,
PSYS_PART_START_ALPHA, 0.5,
PSYS_PART_END_ALPHA,1.0,
PSYS_SRC_MAX_AGE, 0.0,
PSYS_PART_FLAGS, PSYS_PART_INTERP_SCALE_MASK | 0] );
}

default
{
touch_start(integer total_number)
{
integer iTemp = !OnOff;
llMessageLinked(LINK_SET, iTemp, llGetSubString(llGetObjectDesc(), -1, -1), NULL_KEY);
}

link_message(integer sender_num, integer num, string str, key id)
{
if (llGetSubString(llGetObjectDesc(), -1, -1) == str) // is this my group?
{
if (llGetSubString(llGetObjectDesc(), 0, 3) == "Fire";) // am I a burner?
{
if(num)
{
flameParticles();
if (llGetSubString(llGetObjectDesc(), 0, 10) == "Fire Bright";)
llSetPrimitiveParams([
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_POINT_LIGHT, TRUE, <1.0, 1.0, 0.0>, 0.5, 0.25, 0.75
]);
}
else
{
llSetPrimitiveParams([
PRIM_FULLBRIGHT, ALL_SIDES, FALSE,
PRIM_POINT_LIGHT, FALSE, <0.0, 0.0, 0.0>, 1.0, 10.0, 0.75
]);
llParticleSystem([]);
}
}
OnOff = !OnOff; // flip the On/Off state for all prims in this group
}
}
}




btw, i reccommend using a ring like prim (ring, torus, tube) because the particle sourse needs to be turned 90 degrees on the Y axis for the ring to appear correctly. this script makes the ring fit just inside a ring prim that's <0.01, 0.5, 0.5> in scale with a hole size X = 1, Y =.20. adjust the burst radius if you make the prim smaller/bigger
Very Keynes
LSL is a Virus
Join date: 6 May 2006
Posts: 484
05-15-2008 04:34
From: Dekka Raymaker
OMG you should never cook naked!

a genuine LOL, I have coffee all over my screen and keyboard now :)