LSL texture changer script (touch to change texture)
Free LSL texture changer for Second Life: touch to cycle through textures by UUID, one face or the whole linkset, safe for items you sell.
Let people pick a colour or pattern with one click. This texture changer switches the object to the next texture each time it is touched. It works with texture UUIDs instead of names, which matters if you sell or give the item: in a buyer's copy, textures referenced by name often fail because they are not transferable.
// Texture Changer - free LSL script from WhatSL (https://whatsl.com/scripts/lsl-texture-changer-script)
// Free to use, change and put in your own creations, also ones you sell.
//
// Touch to switch to the next texture in TEXTURE_LIST.
// It uses texture UUIDs (not names), so it keeps working in copies you give away or sell.
// To get a UUID: right-click a full-permission texture in your inventory > Copy Asset UUID.
list TEXTURE_LIST = [TEXTURE_PLYWOOD, TEXTURE_BLANK]; // replace with your own texture UUIDs in quotes
integer TEXTURE_FACE = ALL_SIDES; // ALL_SIDES, or one face number such as 0
integer WHOLE_LINKSET = FALSE; // TRUE = change every prim of the linked object
integer OWNER_ONLY = FALSE; // TRUE = only the owner can change it
integer gIndex = 0;
showTexture()
{
string tex = llList2String(TEXTURE_LIST, gIndex);
if (WHOLE_LINKSET) llSetLinkTexture(LINK_SET, tex, TEXTURE_FACE);
else llSetTexture(tex, TEXTURE_FACE);
}
default
{
state_entry()
{
if (llGetListLength(TEXTURE_LIST) > 0) showTexture();
}
touch_start(integer total)
{
if (OWNER_ONLY && llDetectedKey(0) != llGetOwner()) return;
integer count = llGetListLength(TEXTURE_LIST);
if (count == 0) return;
gIndex = (gIndex + 1) % count;
showTexture();
}
}
Frei nutzbar, änderbar und in eigenen Kreationen verwendbar, auch in solchen, die du verkaufst.
How to set it up
- Find the UUID of each texture: in your inventory, right-click a full-permission texture and choose Copy Asset UUID.
- Put the UUIDs in TEXTURE_LIST, each in quotes and separated by commas, for example ["uuid-one", "uuid-two"].
- Add the script to the object and save. Touch it to cycle through the textures.
Settings
- TEXTURE_LIST: the textures to cycle through. The example uses two built-in textures so you can test it straight away.
- TEXTURE_FACE: ALL_SIDES, or one face number to change only that face.
- WHOLE_LINKSET: TRUE changes every prim of a linked object at once.
- OWNER_ONLY: TRUE lets only the owner change the texture.
Tips
- To find a face number, use Select Face in the Edit window and look at the texture tab.
- This script changes classic textures. Objects that use PBR (glTF) materials need a different method.
Frequently asked questions
Why do my textures not change in the copy I sold?
Scripts that set textures by their inventory name fail when the texture is no-transfer for the buyer. This script uses UUIDs, so it keeps working.
Can I change colour instead of texture?
Yes, with a small change: put colours such as <1.0, 0.0, 0.0> in the list and, in showTexture(), use llSetColor(llList2Vector(TEXTURE_LIST, gIndex), TEXTURE_FACE) instead of the two texture lines.
Can I go back to the first texture?
Yes. After the last texture the script starts again at the first one.