|
Artemis Cain
Take it or Leave it
Join date: 11 Apr 2005
Posts: 116
|
05-11-2006 11:45
I am hoping someone might have some guidance for me on this one. Basically, what I am trying to do is set a random texture to a prim when touched. I have placed a few textures in the object and my script looks like this: //script created by Artemis Cain // 5-11-2006
list textures; string random;
default { state_entry() { textures = [1,2,3]; \\ these are the texture names in the objects inventory }
touch_start(integer total_number) { llListRandomize (textures, 1); \\ trying to randomize the sequence of the textures random = llList2String (textures, 0); \\setting "random" to whatever is in space 0 llSetTexture(random, ALL_SIDES); \\setting the random texture to the object } }
the code compiles fine, but it always comes up as texture 1, which would make sense if I didn't want to randomize the list. does anyone know of a way to pull a random number ie: 0, 1, or 2 in this case? should I just generate a random number instead of randomizing the list? any guidance is greatly appreciated! -Art
|
|
Silent Bock
Registered User
Join date: 4 May 2006
Posts: 8
|
05-11-2006 11:52
You might want to just generate a random number. According to the wiki there is a problem with this ( I don't know myself, I am just reading the wiki, I am new to SL ) : http://secondlife.com/badgeo/wakka.php?wakka=llListRandomize&show_comments=1#commentsI am not an experienced scripter so you might want someone else to comment on this  ( that wiki entry hasn't been updated for a while)
|
|
Artemis Cain
Take it or Leave it
Join date: 11 Apr 2005
Posts: 116
|
05-11-2006 11:58
Therein lies the problem. I can't figure out how to randomize the number.
|
|
Cross Lament
Loose-brained Vixen
Join date: 20 Mar 2004
Posts: 1,115
|
05-11-2006 12:01
This ought to work, though I haven't tested it in-world.  default { state_entry() { } touch_start( integer num ) { // Count the number of textures in the object's inventory. integer number_of_textures = llGetInventoryNumber( INVENTORY_TEXTURE ) ; // Generate a random integer between 0 and number_of_textures - 1 (inventory starts counting at 0). integer random = llFloor( llFrand( (float)number_of_textures ) ) ; // Set the texture to the desired randomly-found texture. llSetTexture( llGetInventoryName( INVENTORY_TEXTURE, random ), ALL_SIDES ) ; } }
_____________________
- Making everyone's day just a little more surreal -
Teeple Linden: "OK, where did the tentacled thing go while I was playing with my face?"
|
|
Artemis Cain
Take it or Leave it
Join date: 11 Apr 2005
Posts: 116
|
05-11-2006 12:04
That looks like it works!
that has been bugging me for a while!
Thank you so much!
|
|
Cross Lament
Loose-brained Vixen
Join date: 20 Mar 2004
Posts: 1,115
|
05-11-2006 12:14
From: Artemis Cain Therein lies the problem. I can't figure out how to randomize the number. A quick and easy way to generate random integers between 0 and some integer number max_number is: integer random = llFloor( llFrand( (float)max_number + 1.0 ) ) ; There's a good description of this under the llFrand() entry in the wiki. 
_____________________
- Making everyone's day just a little more surreal -
Teeple Linden: "OK, where did the tentacled thing go while I was playing with my face?"
|