|
Salma Isbell
Registered User
Join date: 10 Jun 2006
Posts: 16
|
09-20-2007 01:48
I'm creating a little builders station, and integrating a texturing organizer/display. I can get it to cycle through the textures, but the the variable continues counting up beyond the last, and below the first texture, after several attempts, I'm uncertain how to make it loop when it reaches the first, and/or last textures. my code far is as follows integer temp; default { link_message(integer sender, integer num, string message, key id) { integer number = llGetInventoryNumber(INVENTORY_TEXTURE); if(num == 4 & message == "forward"  { temp = temp + 1; } else if(num == 4 & message == "back"  { temp = temp - 1; } else { temp = 0; } integer choice = (integer)temp; string name = llGetInventoryName(INVENTORY_TEXTURE, choice); if (name != ""  llSetTexture(name, 6); } } This is operating off two buttons, one for forward, and one for back, there are two additional buttons, not scripted yet, intended to have one display the texture's UUID, either by, to the toucher or just have it set the floating text of the prim to the texture name and UUID. The other will be to give them a copy of it, assuming the texture has proper permissions for that. I haven't started on those buttons yet, as I haven't gotten the cycling working yet, but I felt it important to mention they were goign to be components integrated into the script.
|
|
Haruki Watanabe
llSLCrash(void);
Join date: 28 Mar 2007
Posts: 434
|
09-20-2007 04:34
You have to check whether temp exceeds the max number of Textures...
integer temp;
default {
// Just a suggestion:
state_entry() { temp = 0; // This way, you'll start at the first texture }
link_message(integer sender, integer num, string message, key id)
{ integer number = llGetInventoryNumber(INVENTORY_TEXTURE);
if(num == 4 & message == "forward") { temp = temp + 1; } else if(num == 4 & message == "back") { temp = temp - 1; } else { temp = 0; }
// check if we're at the end of the texture-array or below-zero // this way, when reaching the end of the array, you'll start at // the first entry again
if(temp == number) temp = 0;
// when you go below zero, set temp to the last entry of the texture array
if(temp < 0) temp = number - 1; // the index of the last entry is number - 1
integer choice = (integer)temp; string name = llGetInventoryName(INVENTORY_TEXTURE, choice); if (name != "") llSetTexture(name, 6); } }
HTH
|
|
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
|
09-20-2007 09:23
A kind of shorthand way to get the same result (I think  ) would be temp = (temp + 1) % number; and temp = (number + temp - 1) % number;
|
|
Salma Isbell
Registered User
Join date: 10 Jun 2006
Posts: 16
|
09-20-2007 10:27
Ahh thank you very much,it's always the syntax that bites me, on these new things I'm trying. Hard to find examples for some stuff.
|