Jump to content

Touch Texture Change Script


Talitha Midal
 Share

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

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

Recommended Posts

Hello. I am just playing around with a script and there are no errors. I'm struggling as I don't know why it isn't working.

I was hoping it would scroll through my list of texture UUIDs within the script on the top face of a cylinder whenever it was touched. Even better would be to have an owner only option but that is a little above me at the moment. Baby steps -

 

If anyone could offer a suggestion I would be very thankful...

 

list textures = ["b9e0fda4-7778-30f5-e666-aa4d649827eb",
"d275783b-21ea-91ca-a613-c860ac009e28",
"245c2a5b-5983-84e0-ee31-fb9ec5f0bfef",
"d5d4bbfc-1fac-9b69-b2f7-ae3a5575ac96"];

default
{
    touch_start(integer detected_number)
{
    llSetTexture("textures",0);
}
}

Link to comment
Share on other sites

You need to iterate through the list for each click, select that particular element and then set the texture.

To get your head around the basics of this, add a string variable and then set that string to a number in the list:

String texture

then inside the touch event set that string to an element number in the list:

texture = llList2String(textures,0);

Then set the texture using the string variable, rather than the list:

llSetTexture(texture, 0);

This will set the texture from the list on face 0 of your cylinder.

llSetTexture wants a string value and a prim face.

 

Link to comment
Share on other sites

To scroll on touch would look like below. See the difference?

list textures = ["b9e0fda4-7778-30f5-e666-aa4d649827eb",
"d275783b-21ea-91ca-a613-c860ac009e28",
"245c2a5b-5983-84e0-ee31-fb9ec5f0bfef",
"d5d4bbfc-1fac-9b69-b2f7-ae3a5575ac96"];

integer textures_number;
integer current_index;

default
{
    state_entry()
    {
      textures_number = llGetListLength(textures);
    }

    touch_start(integer detected_number)
    {
      llSetTexture("textures",current_index);
      if(++current_index >= textures_number)
        current_index = 0;
    }
}

Link to comment
Share on other sites

Thanks for your responses.

I am a bit confused to be honest. I tried Ela's sample script to see if I could get my head around it but it didn't work either :/

I have used this one in the past but this was to texture all faces and only has two textures to change between. I couldn't work out how to add more textures to it.

Scripting seems very complicated!

 

string texture1 = "cea52b00-76e6-aa12-782d-8e7b358a68e8";
string texture2= "c5a81d0e-c425-2b07-577b-f1bf5bb5d1a0";
float time = 0.0;
integer side = ALL_SIDES;
 
 
integer currentstate;
switch(string texture)
{
    llSetTexture(texture, side);
    currentstate = ~currentstate;
    llSleep(time);
}
default
{
    touch_start(integer total_number)
    {
        if(currentstate)
            switch(texture1);
        else
            switch(texture2);
    }
}

Link to comment
Share on other sites

Ahh... that's because I basically copied your sample :)

touch_start(integer detected_number)
    {
      llSetTexture("textures",current_index);
      if(++current_index >= textures_number)
        current_index = 0;
    }

would not work of course because you have quotes around textures: "textures", so the llSetTexture() sees it as a string.What you need there is a list element

Should be:

  touch_start(integer detected_number)
    {
      llSetTexture(llList2String(textures,current_index));
      if(++current_index >= textures_number)
        current_index = 0;
    }

Link to comment
Share on other sites

Start using an external editor like LSL Editor that gives fairly helpful error messages and that you can use when you are not logged in to SL.  You can see a range of choices at http://wiki.secondlife.com/wiki/LSL_Alternate_Editors .

There are many ways to start learning LSL.  One way is to work through some of the tutorials at http://wiki.secondlife.com/wiki/LSL_Tutorial and elsewhere.   They at least give you a feel for the structure of the language andd the syntax of its functions. The heart of scripting, however, is logic.  That's harder to pick up from tutorials than it is to learn by example. I'd recommend starting to examine sample scripts to see how they work.  Play with them, modify them to see what your changes accomplish, and gradually try writing your own.  There are freebie scripts all over SL and in wb sites, as well as in the LSL library and in examples buried throughout the wiki. 

Try not to be discouraged when things don't work quite the way you expect.  You often learn more from mistakes than when things always do what you predict they will.  As you start working on your own projects and have questions, bring them here.  That's exactly what this forum is for.   Welcome aboard.

Link to comment
Share on other sites


Talitha Midal wrote:

What is compiler access?

in this case she meant being inworld where saving the script would have caught the error in what she posted.... saving a script compiles it, so it acts like a spellchecker for scripting.

@Ela:

we all do it don't sweat it.... it's why it's good to have a community to catch the little errors when we're trying to quickly help.

Link to comment
Share on other sites

Builders Brewery offer some very good scripting classes.   I would also strongly recommend checking out the College of Scripting, which has a wealth of examples and walk-throughs (someone described it as "Like the Ivory Tower of Prims, only for scripts), and a very active help group.   Scripts and Script Academy are good, too; there's usually someone around who can help out with any particular problem.

Link to comment
Share on other sites

  • 2 weeks later...

I've been tinkering around with the script I set out to create in this thread and have hit a stumbling block. I wanted to see if I could make it so that only I, as owner, could change the texture. This came about when I realised that if I wanted to control it, rather than visitors changing the texture all the time, I needed to add something.  I visited the College of Scripting and did some wiki searching etc. I got this far. It accepts the script and saves it but then nothing happens, no texture changing anymore. I think I am missing a chunk but am not sure what. Can anyone help me along?

 

list textures = ["123"];

integer textures_number;
integer current_index;

default
{
    state_entry()
    {
      textures_number = llGetListLength(textures);
    }

    touch_start(integer detected_number)
    {if(llDetectedKey(0) == llGetOwner())
          {llSetTexture(llList2String(textures,current_index),0);
      if(++current_index >= textures_number)
        current_index = 0;
    }
}
}

Link to comment
Share on other sites

I think the problem is with your list of textures, which is a single string, that is "123" (as a literal string, rather than an integer).

If you're hard-coding the textures, it should be something like 

 

list textures =[//these are the uuids of some public domain textures from the Blender.org collection	"39359302-6f83-4717-eeca-cbfa7482d6cb",	"cae9a7b6-ddf5-986f-6328-885bea69cee4",	"f17a9afd-00d4-ab5e-60f3-756afdf649f1"		];integer textures_number;integer current_index;default{	state_entry()	{		textures_number = llGetListLength(textures);	}	touch_start(integer detected_number)	{if(llDetectedKey(0) == llGetOwner())		{llSetTexture(llList2String(textures,current_index),0);				if(++current_index >= textures_number)					current_index = 0;			}		}}

 

Link to comment
Share on other sites

You've almost got it.  Just missing one bracket.  I think your problem is basically that you weren't careful to format the script cleanly.  If you are always obsessive about indenting each script element with a new scope (like me  :smileytongue: ), it will be easier to see where you need brackets, and to count them. Here's a clean version......

list textures = ["123"]; // This list contains the name of one texture, called "123"integer textures_number;integer current_index;default{    state_entry()    {        textures_number = llGetListLength(textures);    }    touch_start(integer detected_number)    {        if(llDetectedKey(0) == llGetOwner())        {            llSetTexture(llList2String(textures,current_index),0);            if(++current_index >= textures_number)            {                current_index = 0;            }        }    }  // You were missing this bracket to close the touch_start event}

Notice that as you wrote it, the list called textures only has one element, so there won't be much texture switching going on until you lengthen that list.   If you're interested, you can compress this script a little by changing the middle of the touch_start event ....

        if(llDetectedKey(0) == llGetOwner())        {            llSetTexture(llList2String(textures,(++current_index)%textures_number),0);        }

 ETA:  Ah... no.  Sorry. I miscounted them myself. :=/   I was thrown off by the fact that you didn't put brackets around the scope of your innermost if condition.  ALWAYS put brackets around every scope.   So, as we both pointed out, the reason there's no changing happening is that you only have one texture in the list.

Link to comment
Share on other sites

I should have known it would be a rogue bracket, now I feel silly. LOL.

You mention indenting brackets and I have noticed how scripters do that. But I wasn't sure when to indent and when not to, as some of the brackets seem in line with each other.

 

(I seem to be having inworld issues now trying to open the object and the script I am working on)

Link to comment
Share on other sites

There are few "rules" in this business except consistency and readability.  In general, it's easier to keep track of blocks of code that belong together if you indent each new level of code by 4 spaces.  Beyond that, you'll get disagreement about how much white space to create (I like a lot, so I can see what's going on) and where to put the curly bracket that opens each new scope (I always start on a fresh line).  I also add comments at critical spots, especially if I am writing a script for a client, but even if they are just for me.  It's amazing how quickly I forget just why I wrote code in a specific way. Whatever style you choose, stick with it.  You'll have fewer problems recognizing the common, embarrasing mistakes that we all make.

Link to comment
Share on other sites

Ok, I am going nuts.  I copied the script below from an earlier message in this thread. All I changed is the texture UUIS's. The first time I save it to a linkset, it works fine.  I was trying to modify it and get getting errors when saving, and then it would not work.  I could delete it and start over, and it would work fine.  Eventually I disovered that I could not do ANYTHING to it without breaking it.  After the initial save, even if I add a space then delete the space, it fails upon saving.  Apparently I cannot edit a script without breaking it.  Any ideas what may be going on? (using Phoenix).

-----------------------------------------------------------------------------

list textures = ["b9e0fda4-7778-30f5-e666-aa4d649827eb",
"d275783b-21ea-91ca-a613-c860ac009e28",
"245c2a5b-5983-84e0-ee31-fb9ec5f0bfef",
"d5d4bbfc-1fac-9b69-b2f7-ae3a5575ac96"];

integer textures_number;
integer current_index;

default
{
state_entry()
{
textures_number = llGetListLength(textures);
}

touch_start(integer detected_number)
{
llSetTexture("textures",current_index);
if(++current_index >= textures_number)
current_index = 0;
}
}

Link to comment
Share on other sites

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