Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Touch texture changer

Elfeux Yeuxdoux
Registered User
Join date: 13 Oct 2006
Posts: 4
10-15-2006 08:14
Hi all,

Right now I wrote a script where every time you touch the object it changes to the next texture in the inventory. However, the way I have it written now it is necessary to change the name of each texture to "texture#". Is there anyway to do this using llGeti|Invetory and a list?
Bellow is a copy of what I have written so far.

Thanks for all the help,
Elfeux


integer texture = 0;
default
{
touch_start(integer total_number)
{
texture = (texture + 1) % 4 ;
string texturename = "texture" + (string)texture ;
llSetTexture(texturename, ALL_SIDES) ;

if( texture == 0 )
{
llSetScale(< 0.01, 2.34, 2.355 >;) ;
}
if( texture == 1 )
{
llSetScale(< 0.01, 3.657, 2.724 >;) ;
}
if( texture == 2 )
{
llSetScale(< 0.01, 3.657, 2.724 >;) ;
}
if( texture == 3 )
{
llSetScale(< 0.01, 3.66, 2.745 >;) ;
}
if( texture == 4 )
{
llSetScale(< 0.01, 3.66, 2.73 >;) ;
}
if( texture == 5 )
{
llSetScale(< 0.01, 3.66, 2.745 >;) ;
}
}
}
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
10-15-2006 08:57
Yes.

You make your list using llGetInventoryNumber(INVENTORY_TEXTURE) to give you the number of textures, and then looping that through llGetInventoryName(INVENTORY_TEXTURE, i) to build it up.

Then... a pointer variable that advances with each touch, and since it's one-way when your pointer == that first inventory number you got, set it back to 0.
_____________________
Eloise's MiniMall
Visit Eloise's Minimall
New, smaller footprint, same great materials.

Check out the new blog
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
10-15-2006 13:17
You appear to be using the texture number resulting from a modulus call to set the scale. This would potentially require that you revisit your code every time you updated the textures as the ordering of items could change.

If this is the case I'd opt for a notecard driven system containing both the texture and the scale factors for each entry:
CODE

Funny texture A=< 0.01, 2.34, 2.355 >
Second Texture Name=< 0.01, 3.657, 2.724 >
CODE
Elfeux Yeuxdoux
Registered User
Join date: 13 Oct 2006
Posts: 4
10-15-2006 18:26
Hi Newgate,

I am sorry to ask, however would you mind explaining in further details how you would set up this note card and the accompanied script.

Thanks a lot for all your help,
Elfeux
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
10-15-2006 20:19
Do you really need to set the scale of each texture? If so and there are a lot of textures then it can become laggy or run into too many IF's . If you don't need that then it is much easier. If you do need to set the scale of each individual texture then you could still get the number of textures, and increment by one each time. Store the scale values in each texture description and read the description when it picks that texture.

Take this script and dump it in a prim with a bunch of textures. Every time you touch it, it will change to a different random texture. If this is more inline with what you want to do then let us know. It won't take much to see how many textures are in the box and then change to the next one each time you touch it instead of a random texture.

CODE

default
{

touch_start(integer total_number)
{
integer number = llGetInventoryNumber(INVENTORY_TEXTURE);
float rand = llFrand(number);
integer choice = (integer)rand;
string name = llGetInventoryName(INVENTORY_TEXTURE, choice);
if (name != "")
llSetTexture(name, ALL_SIDES);
}
}
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
10-16-2006 23:16
CODE

//<------Texture Thing-------------------------------------------------------------------------->//

// options
integer face = ALL_SIDES;
float thickness = 0.01;

// globals
list image_data;

integer total_list_entrys;
integer current_image;

string notecard;

//Script
default
{
state_entry() {llOwnerSay("Touch to Setup");}

touch_start(integer total_number)
{
notecard = llGetInventoryName(INVENTORY_NOTECARD,0);
state get_texture_data;
}
}

state get_texture_data
{
state_entry()
{
llGetNotecardLine(notecard,0);
llOwnerSay("reading data");
}

dataserver(key queryid, string data)
{
if (data != EOF && data != " ")
{
image_data += llParseString2List(data,["|"],[]);
++current_image;
llGetNotecardLine(notecard,current_image);
}

else
{
current_image = 0;
if (llGetInventoryNumber(INVENTORY_TEXTURE) != (llGetListLength(image_data)/3))
{
state error;
}

else
{
total_list_entrys = (llGetListLength(image_data) - 1);
state running;
}
}
}
}

state running
{
state_entry(){llOwnerSay("ready");}
touch_start(integer t)
{
llSetTexture(llGetInventoryKey(llList2String(image_data,current_image)), face);
llSetScale( <thickness,
(float)llList2String(image_data,current_image +1),
(float)llList2String(image_data,current_image +2)>
);
if ((current_image +3) < total_list_entrys) current_image += 3;
else current_image = 0;
}
}


state error
{
state_entry()
{
llOwnerSay("check your notecard or your object inventory for errors, script halted");
}
}


example notecard
CODE

Crazed_Ren|2.34|2.355
cards|3.657|2.724
cards_sl|3.66|2.745
more spiral fun layer 1|3.66|2.73
new circle|3.66|2.745


drop your textures into the objects inventory, put their names in a notecard as above (name|scaleY|scaleZ) a constant thickness on X is assumed in the script
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
10-17-2006 00:01
From: Elfeux Yeuxdoux
Hi Newgate,

I am sorry to ask, however would you mind explaining in further details how you would set up this note card and the accompanied script.

Thanks a lot for all your help,
Elfeux


Osgeld has covered pretty much what I'd do but if you want my solution I'll post it later.

One thing I'd change to your script Jesse, Add a Changed even to reset when ever new textures are added to the inventory

CODE
Changed(integer change) 
{
// Test for a changed inventory
if (change & CHANGED_INVENTORY)
{
llResetScript();
}
}
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
10-17-2006 06:13
Yep, that was just a script from the library, checking to see if he really needed to change scale. But big mistake in my post was :

"Store the scale values in each texture description and read the description when it picks that texture."

Errrrrrrr. WIshful thinking on my part. You of course can't read a description from inventory, only the description of the prim that the script is in. Hopefully LL will one day allow this as it does seem to be a logical function. The description field is such a handy, albiet limited, permanent storage area.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Elfeux Yeuxdoux
Registered User
Join date: 13 Oct 2006
Posts: 4
10-17-2006 09:20
Thank you guys!!!
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
10-17-2006 09:32
From: Jesse Barnett
Yep, that was just a script from the library, checking to see if he really needed to change scale. But big mistake in my post was :

"Store the scale values in each texture description and read the description when it picks that texture."

Errrrrrrr. WIshful thinking on my part. You of course can't read a description from inventory, only the description of the prim that the script is in. Hopefully LL will one day allow this as it does seem to be a logical function. The description field is such a handy, albiet limited, permanent storage area.



Well I miss read it and thought you meant the name which would work.
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
10-17-2006 18:42
From: Newgate Ludd
Osgeld has covered pretty much what I'd do but if you want my solution I'll post it later.

One thing I'd change to your script Jesse, Add a Changed even to reset when ever new textures are added to the inventory


that blob of script i posted could be done better.. just kinda winged it out there before bed, and to add onto it i tried to keep the script inflated so the starting scripter might be able to follow it

(really expected some nitpicking on it .... but im not goning to complain)

i should have put in a changed event under "state running", it crossed my mind but it ended up getting real late and it just never made it in there

From: Jesse Barnett

"Store the scale values in each texture description and read the description when it picks that texture."


yea that would be really nice

From: Elfeux Yeuxdoux
Thank you guys!!!


your welcome
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
10-17-2006 22:07
CODE

//<------TextureThing--take 2-------------------------------->//
//<---textures in object inventory--------------------------->//
//<---textures by UUID--------------------------------------->//
//<---reads mixed mode direct from notecard ---------------->//



// options
integer face = ALL_SIDES;
float thickness = 0.01;

// globals
integer current_image;
string notecard;

//script
default
{
state_entry()
{
notecard = llGetInventoryName(INVENTORY_NOTECARD,0);
llOwnerSay("ready");
}

touch_start(integer t)
{
llGetNotecardLine(notecard,current_image);
}

//not checking your dataserver reqest key is unwise...
//in complex dataserver events

dataserver(key na, string input)
{
if (input != EOF && input != " ")
{
list output = llParseString2List(input,["|"],[]);
llSetTexture(llList2String(output,0),face);
llSetScale(
<thickness,
(float)llList2String(output,1),
(float)llList2String(output,2)>
);
++current_image;
output = [];
}

else
{
current_image = 0;
llGetNotecardLine(notecard,current_image);
}
}
}



this script loaded with data ... 15426 bytes free
old script loaded with data .... 14470 bytes free

with the old script, if you have 10 textures instead of 5 you loose about 2kb instead of 1

if you have 50 textures you burn 10kb of space (ish / rough numbers)

vs this way you have only one data chunk loaded up at a time (instead of all of them)

and you can cram upto 64 kb of data on a notecard regardless of formating (thats a good amount of textures and y-x scale info)
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
10-18-2006 05:10
From: Osgeld Barmy
that blob of script i posted could be done better.. just kinda winged it out there before bed, and to add onto it i tried to keep the script inflated so the starting scripter might be able to follow it

(really expected some nitpicking on it .... but im not goning to complain)



Osgeld, no nit picking was intended, purely my turn of phrase. I meant you had covered all the points needed and that posting my script would be superflous.
My apologies for an unintended slight.
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
10-18-2006 12:26
no need to appoligise cause you didnt nit pick :)
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
10-19-2006 02:58
From: Osgeld Barmy
no need to appoligise cause you didnt nit pick :)



ROFL, correct I completely misread your comment.
You wanted some nit picking ok...
/me Rolls up sleeves....
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
10-19-2006 06:26
heeheeheehee

Osgeld,
You misspelled "request";

"//not checking your dataserver reqest key is unwise... "

Now do you feel better?????
LOL
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
10-19-2006 09:33
sniffle nooooooo


:)