Jump to content

Fixing a fire script


Mikolan Lutrova
 Share

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

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

Recommended Posts

Hello!

Trying to get a fire to work with an on/off toggle via touch and came across the following script. It toggles certainly, but something is backwards. Goal is to set texture transparency=100% AND turn off light source when "fire off". Upon clicking the fire, it should turn on light source and set texture transparency to 0%. This is with 3 prims linked to a parent prim where the script resides (all labeled "flames"). However, the script seems to set texture transparency at 100% and light on when "fire on", texture transparency at 0% and light off when "fire off". Hope I'm making sense but basically, I'm just trying to make the flames go off and completely transparent when I click it to turn off. I google searched the heck out of this and coming up blank.

Please keep in mind that I understand about 1% of all this scripting stuff so if you would, please give it to me stupid simple.

 

 

// Set this variable to the name of the prims that are textured with the flame texture.

string  FLAME_PRIM_NAME = "flames";

float   Alpha = 1.0;
integer Glow = 2;
list    light;

default
{
    state_entry()
    {
        light = llGetPrimitiveParams([PRIM_POINT_LIGHT]);
    }

    touch_start(integer total_number)
    {
        if (Glow == 0) {
            Alpha = 0.0;
            Glow = 2;
            llWhisper(0, "Fire on");
        } else {
            Alpha = 1.0;
            Glow = 0;
            llWhisper(0, "Fire off");
        }
        
        light = llListReplaceList(light, [Glow], 0, 0);

        integer link;
        for (link = 1; link <= llGetNumberOfPrims(); link++) {
            if (llGetLinkName(link) == FLAME_PRIM_NAME) {
                llSetLinkAlpha(link, Alpha, ALL_SIDES);
                llSetLinkPrimitiveParams(link, [PRIM_POINT_LIGHT] + light);
            }
        }
    }
}

Link to comment
Share on other sites

That's not a particularly well-written script, but you can make it do what you want by replacing Alpha = 0.0; with Alpha = 1.0; (and vice-versa) in the touch_start event.  That will at least fix the problem you identified.  It won't do a thing about the fact that half of your fire is not in the fireplace.  More of your flames are on the hearth than in the logs.  🙃

Link to comment
Share on other sites

35 minutes ago, Rolig Loon said:

That's not a particularly well-written script, but you can make it do what you want by replacing Alpha = 0.0; with Alpha = 1.0; (and vice-versa) in the touch_start event.  That will at least fix the problem you identified.  It won't do a thing about the fact that half of your fire is not in the fireplace.  More of your flames are on the hearth than in the logs.  🙃

LOL yes, the prims are all scattered around a bit as I was trying to dig out the root prim while also trying to delete a bad script installed in every prim that wasn't working at all and install the current script in the root. If this was actual fire, my entire problem would be nullified given I'd likely burn down the entire house...

I can at least happily say I didn't write the script. I found it online and was the only one that seemed to even remotely work the way I needed it to. And okay, what you said certainly fixed the light source issue. So thankyou! However, with the light source gone, I realized now that the glow isn't changing as it should. So the light goes off and the texture turns transparent but the texture glow remains when it should change to 0 or no glow.

Link to comment
Share on other sites

Well, that's because your script really doesn't affect glow at all.  The parameter that is named "Glow" in that script is just a toggle that turns a point source light on and off.  (And has a silly, non-consequential coding sloppiness in it.  That variable should either be equal to 0 or 1.  Not 2.  Please change that in the two places where it says Glow = 2 ) The reason that there is any real glow in your fire prim is that you have set a value for Glow in your viewer's editor panel manually.   From the looks of it, it's set to something excessive, like 1.0.  I doubt that you really need any glow at all, frankly, so I suggest just setting it to 0.0 and leaving it there.  If you truly want glow to turn on and off with your flame texture, I suggest changing the code line that says

llSetLinkPrimitiveParams(link, [PRIM_POINT_LIGHT] + light);

and making it say

llSetLinkPrimitiveParamsFast(link, [PRIM_POINT_LIGHT] + light + [PRIM_GLOW, link, 0.1*Glow]);

By the way, this script will only behave properly if it is in the prim named "flames" and if that prim is the root prim, but I'm guessing that you have figured that out.

 

Link to comment
Share on other sites

32 minutes ago, Rolig Loon said:

Well, that's because your script really doesn't affect glow at all.  The parameter that is named "Glow" in that script is just a toggle that turns a point source light on and off.  (And has a silly, non-consequential coding sloppiness in it.  That variable should either be equal to 0 or 1.  Not 2.  Please change that in the two places where it says Glow = 2 ) The reason that there is any real glow in your fire prim is that you have set a value for Glow in your viewer's editor panel manually.   From the looks of it, it's set to something excessive, like 1.0.  I doubt that you really need any glow at all, frankly, so I suggest just setting it to 0.0 and leaving it there.  If you truly want glow to turn on and off with your flame texture, I suggest changing the code line that says

llSetLinkPrimitiveParams(link, [PRIM_POINT_LIGHT] + light);

and making it say

llSetLinkPrimitiveParamsFast(link, [PRIM_POINT_LIGHT] + light + [PRIM_GLOW, link, 0.1*Glow]);

By the way, this script will only behave properly if it is in the prim named "flames" and if that prim is the root prim, but I'm guessing that you have figured that out.

 

Sorry, the glow= 2 is actually from me having no clue really what I'm doing and trying to play around with it to make it work. :} So I changed it back.

Unfortunately, replacing the code line as you instructed, didn't have any effect. It still stays at a setting of 0.2. Which, yes, is where it was originally set manually via the editor panel.

And now, I have no idea what I changed but something is resetting the light color to black with intensity, radius and falloff all being 0.

Honestly, I don't know how y'all do this stuff. I would be completely bald by the end of a week from pulling my hair out just trying to solve this stuff....

 

Link to comment
Share on other sites

This is one of the challenges of scripting from a distance.  I can't see the effect of any script suggestions I make, so I can't immediately say "Ooops!" and fix a typo.  So, I made a mistake.

I had to write  llSetLinkPrimitiveParamsFast(link, [PRIM_POINT_LIGHT] + light + [PRIM_GLOW, link, 0.1*Glow]);  but that variable I just highlighted in red should be the face that is supposed to have glow, not the link.  The problem is that I don't know what face that is, at least from a distance, and it's hard to explain how to find out, except to suggest that you try replacing that word link with an integer and see what happens.  Start with 0.  If that doesn't work, try 1, then 2, and 3...  Unfortunately, each time you make a bad guess, it will put the glow where you don't want it, so you'll have to use the Glow setting in your viewer to manually set the glow on everything to zero in between tests.

 

Link to comment
Share on other sites

6 hours ago, Rolig Loon said:

llSetLinkPrimitiveParamsFast(link, [PRIM_POINT_LIGHT] + light + [PRIM_GLO

 

6 hours ago, Rolig Loon said:

This is one of the challenges of scripting from a distance.  I can't see the effect of any script suggestions I make, so I can't immediately say "Ooops!" and fix a typo.  So, I made a mistake.

I had to write  llSetLinkPrimitiveParamsFast(link, [PRIM_POINT_LIGHT] + light + [PRIM_GLOW, link, 0.1*Glow]);  but that variable I just highlighted in red should be the face that is supposed to have glow, not the link.  The problem is that I don't know what face that is, at least from a distance, and it's hard to explain how to find out, except to suggest that you try replacing that word link with an integer and see what happens.  Start with 0.  If that doesn't work, try 1, then 2, and 3...  Unfortunately, each time you make a bad guess, it will put the glow where you don't want it, so you'll have to use the Glow setting in your viewer to manually set the glow on everything to zero in between tests.

 

Awesome! Set it to 0 and immediately it worked perfectly.

https://gyazo.com/5645d5bb5fa491a44976937805dcf5b4

And I'm definitely not gonna be the one to say shame on you or anything for a mistake. Your mistake is still a far cry from my "well let me just try this!" approach.

Thank you SOO much for your help. No BS, even with all the textures and mesh makers, people like you is what makes the heart beat in our world.

  • Like 2
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1181 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...