Jump to content

Texture change on touch (I need help, thanks!)


6dominiq9
 Share

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

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

Recommended Posts

Hello! 

So, I've bought a script, but I have no idea how to modify it, because I'm not a scripter, I've tried for 5h but without any results.

I want to have 3 textures, not 2 textures. But at the part with (if, else, if else and everything.. I got lost)

    touch_start(integer total_number)
    {
        if(currentstate)
            switch(texture1);
        else
            switch(texture2);
    }
}

 

Can someone edit it or help me? Please and thank you so much! 

Here is the full script. :)

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
string texture1 = "TEXTURE 1";//UUID of texture 1 (or inventory name if in inventorY)
string texture2= "TEXTURE 2";//UUID of texture2
string texture3= "TEXTURE 3";//UUID of texture3
float time = 0.0;//time to sleep in seconds
integer side = ALL_SIDES;//which side to change texture on


/////////////
//
integer currentstate;//the state its in either TRUE or FALSE
switch(string texture)
{
    llSetTexture(texture, side);
    currentstate = ~currentstate;//swith states
    llSleep(time);
}
default
{
    touch_start(integer total_number)
    {
        if(currentstate)
            switch(texture1);
        else
            switch(texture2);
    }
}

 

Link to comment
Share on other sites

I am SO not a scripts person and I am sure someone will come along with the answer soon -- but as I looked at this I think you need  

 else if  

instead of else because the original script only had TWO choices and you are making it three.

 

Just putting this in there in case I am correct which means that I learned SOMETHING in a decade (granted not much). 

 

  • Thanks 1
Link to comment
Share on other sites

Chic is pretty much correct, that if-else needs a third check in the middle.

But since those checks depend on the global variable currentstate, the switch function needs to be edited so that it gives currentstate a third value as well, if you want it to keep the same structure. This should work, unless I made a typo:

string texture1 = "TEXTURE 1"; //UUID of texture 1 (or inventory name if in inventorY)
string texture2= "TEXTURE 2";  //UUID of texture2
string texture3= "TEXTURE 3";  //UUID of texture3
float time = 0.0; //time to sleep in seconds
integer side = ALL_SIDES; //which side to change texture on


integer currentstate; //the state its in either TRUE or FALSE
switch(string texture)
{
    llSetTexture(texture, side);
    currentstate = ++currentstate % 3; //swith states
    llSleep(time);
}

default
{
    touch_start(integer total_number)
    {
        if (currentstate == 0)
            switch(texture1);
        else if (currentstate == 1)
            switch(texture2);
        else
            switch(texture3);
    }
}

The magic happens on this line:

currentstate = ++currentstate % 3; //swith states

Which does three things:

  1. increment currentstate by one
  2. modulo currentstate by 3
  3. store the result over the old one

In short, currentstate will cycle between 0, 1, and 2.

Edited by Wulfie Reanimator
  • Thanks 1
Link to comment
Share on other sites

Quote

So, I've bought a script

I hate it when people buy sub-par scripts when I'd hand them a better script for free for something that simple:

//list of texture UUIDs. Textures in the same prim will be included automatically.
list gTextures = 
[  //remove or replace the next few lines
   "5748decc-f629-461c-9a36-a35a221fe21f", // TEXTUTE_BLANK
   "38b86f85-2575-52a9-a531-23108d8da837" //(invisiprim) // no final comma. 
];
integer gNtextures; // = llGetListLength(gTextures);
integer gIndex=-1;
default
{
  state_entry()
  {  gNTextures=llGetListLength(gTextures);
  }
  touch_start()
  {  integer invN = llGetInventoryNumber(INVENTORY_TEXTURE);
     ++gIndex;
     if(gTextureIndex<gNtextures)
     {  llSetTexture(ALL_SIDES,llList2String(gTextures,gIndex));
     }else if(gTexture<gNtextures+invN)
     {	llSetTexture(ALL_SIDES,llGetInventoryName(INVENTORY_TEXTURE,gIndex-invN);
     }else
     {  llSetTexture(ALL_SIDES,llList2String(gTextures,gIndex=0));
     }
  }
}

Assuming I didn't make any mistakes, you should be able to use this to cycle through as many textures as you like, specifically named uuids hard coded into the script, and all textures in the prim's inventory.

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
On 4/15/2021 at 4:22 AM, Quistessa said:

Assuming I didn't make any mistakes, you should be able to use this to cycle through as many textures as you like, specifically named uuids hard coded into the script, and all textures in the prim's inventory.

You? Mistakes? In scripts?!?

Is nothing sacred???!??? 😲🙃

  • Haha 1
Link to comment
Share on other sites

  • 1 year later...

Someone poked me about the script I posted above. Apparently I did have a lot of sloppy mit-steaks (delicious!) Mostly just matching parentheses and inconsistent names, and one spot where I used the wrong variable in a calculation.

//list of texture UUIDs. Textures in the same prim will be included automatically.
list gTextures = 
[  //remove or replace the next few lines
   "5748decc-f629-461c-9a36-a35a221fe21f", // TEXTUTE_BLANK
   "38b86f85-2575-52a9-a531-23108d8da837", //(invisiprim) // no final comma. 
   "6c802d30-49ba-b17b-ed83-f5789e05a936", // ALPHA
   "b2d5eb75-b4bf-7763-28dc-d46a03f8e992"
];
integer gNTextures; // = llGetListLength(gTextures);
integer gTextureIndex=-1;
default
{
  state_entry()
  {  gNTextures=llGetListLength(gTextures);
  }
  touch_start(integer n)
  {  integer invN = llGetInventoryNumber(INVENTORY_TEXTURE);
     ++gTextureIndex;
     if(gTextureIndex<gNTextures)
     {  llSetTexture(llList2String(gTextures,gTextureIndex),ALL_SIDES);
     }else if(gTextureIndex<gNTextures+invN)
     {  llSetTexture(llGetInventoryName(INVENTORY_TEXTURE,gTextureIndex-gNTextures),ALL_SIDES);
     }else
     {  llSetTexture(llList2String(gTextures,gTextureIndex=0),ALL_SIDES);
     }
  }
}

Fixed! (probably).

  • Thanks 1
  • Confused 1
Link to comment
Share on other sites

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