Jump to content

Modifying a texture script


Kakukkfu Yosuke
 Share

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

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

Recommended Posts

Hi

I have an object with 3 textures in it. First texture loads on rez, than when an object named "bullet hits" this object it loads the next texture and so on until the third texture loads than it stops. Than another object called "bullet2" hits the object and I want to load texture 2, then when  again until texture 1 loads , than stop.

The actual script almost work, but "bullet2" have to hit two times the object until texture 2 loads. Actually it has to work like a slideshow, "bullet1" loads the textures forward and "bullet2" backward until last texture reached.

Thanks

 

 

integer numberTextures = 0;
integer currentTexture = 1;

default
{
    on_rez(integer start_param)
    {
        llResetScript();
         llSetTexture(llGetInventoryName(INVENTORY_TEXTURE, currentTexture), ALL_SIDES);
    }
   state_entry()
    {
        numberTextures = llGetInventoryNumber(INVENTORY_TEXTURE);
    }

    collision_start(integer who)
    {
       if (llDetectedName(0) == "bullet")
       {
        llSetTexture(llGetInventoryName(INVENTORY_TEXTURE, currentTexture), ALL_SIDES);
        if (currentTexture < numberTextures -1)
            currentTexture++;
        }
        //---------------------------
        if (llDetectedName(0) == "bullet2")
       {
        llSetTexture(llGetInventoryName(INVENTORY_TEXTURE, currentTexture), ALL_SIDES);
        if (currentTexture > 0)
            currentTexture--;
        }
    }

    changed(integer what)
    {
        if (what & CHANGED_INVENTORY)
            llResetScript();
    }
}

Link to comment
Share on other sites

Hi  Kakukkfu,

If multpie strikes by bullets have advanced the texture to the last one, the first bullet2 to strike your target will simply load that texture again. It'll take a second bullet2 to change the texture. That's because you apply the textures before advancing the slide count. So, each bullet that strikes, whether "bullet" or "bullet2", applies the texture selected by the previous strike. At each collision, you want to first compute the proper texture to display, then display it. So move your llSetTexture() calls to after your slide selection logic, and change that logic accordingly.

There's another problem in the script. The first time a texture is applied, it's not likely to be in the texture cache. As a result, the target will momentarly flash grey, then show the progressive texture load. That'll look icky. Subsequent texture changes will go better, as everything has been pulled into cache. You should either preload all the textures you'll need (by texturing other faces of the same prim, with an alpha of zero so you don't see them) or create one larger texture, tiled with the various images you'll need. Then you'd animate the texture at each strike, moving to the next tile in the sequence. You'd use llSetTextureAnim for that, and you'd want to load the texture on rez, so you don't see the rezzing sequence on the first bullet strike.

Good luck!

ETA: Another way to view the error in your script logic is that each collision event displays a texture, then calculates which texture should be shown by the next bullet strike. That's premature. You don't know which kind of bullet the next will be.

  • Like 1
Link to comment
Share on other sites

Thank you very much for your long exlpanation. The script now works!

Just one more questions here. How do I set a texture on 2 sides, I don't find any information about this. Should I write:

llSetTexture(llGetInventoryName(INVENTORY_TEXTURE, currentTexture), 1);

llSetTexture(llGetInventoryName(INVENTORY_TEXTURE, currentTexture), 3);

llSetTexture(llGetInventoryName(INVENTORY_TEXTURE, currentTexture), 4);

or there is a shorter version in one line.

 

Thanks

 

Link to comment
Share on other sites

While llSetTexture is an easy function to begin with, it has the disadvantage of a built-in 0.2 seconds delay. So if you call it three times, it's kinda slow.

Alternatively you can use another function, without any built-in delay, which will set these 3 faces in a single function call like this;

string sTex = llGetInventoryName(INVENTORY_TEXTURE, currentTexture);
llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_TEXTURE, 1, sTex, <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0,PRIM_TEXTURE, 3, sTex, <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0,PRIM_TEXTURE, 4, sTex, <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0]);
Link to comment
Share on other sites

  • 2 weeks later...

Yes, you have to use llSetLinkPrimitiveParamsFast.  That's the function without the built-in delay, and it works just fine on mesh objects.  Do be sure that you are addressing the correct face on the correct prim when you use it (just follow Arton's example). 

Link to comment
Share on other sites

What Rolig said. Probably you have just to figure out linknumbers, and face numbers.

You can drop in this little script, which tells the linknumber, and the face number where you touched the object, to figure out which is what.

default{    touch_start(integer total_number)    {        llOwnerSay("Link number: " + (string)llDetectedLinkNumber(0));        llOwnerSay("Face: " + (string)llDetectedTouchFace(0));    }}
Link to comment
Share on other sites

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