Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Random texture Rotation Help Needed

Enkidu Recreant
Registered User
Join date: 27 Aug 2007
Posts: 28
09-06-2008 19:07
Hi

I'm a rookie scripter and I'm creating a Tarot card. The card contains the tarot textures and displays each at random on touch. If the owner says "Reset" it rests back to the cardback texture. That much works.

With Tarot, cards can be either way up and the orientation affects the meaning. So...I am trying to further adapt the script so that when the card is touched, it generates a random number 0 or 1. If the random number is 1, then the texture is rotated 180 degrees. I tested the random number generator part out separately, but now i have added it in, it always seems to generate the same number.

This is the script

string texture;
string keyword = "reset";
integer channel = 0;

integer Handle;
default
{
state_entry() {
Handle = llListen (channel, "", llGetOwner(), "";);
}
changed(integer change)
{
if (change & CHANGED_OWNER)
llResetScript();
}
listen(integer chan, string name, key id, string msg)
{
if (msg == keyword) {
llSetTexture("13de8f92-9da6-c5c8-1ca0-48f7446435cb", ALL_SIDES);

llListenRemove(Handle);
Handle = llListen (channel, "", llGetOwner(), "";);
}
}
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);

float random = llFrand(1);
integer direction = (integer)random;
if (direction = 0)
llRotateTexture(PI/2, ALL_SIDES);
}
}


I know there is probably redundant code in here, i have cannibalised other scripts. Also, I know that PI/2 only rotates by 90 degrees. I was going to deal with that when I got the other bit to work, but any advice on the correct rotation value would be a great help.

Any help on getting this to work will help save my remaining hairs.

Cheers
Talon Brown
Slacker Punk
Join date: 17 May 2006
Posts: 352
09-06-2008 19:44
You need to use llFrand(2.0) instead of 1. When you typecast it to an integer you are losing the decimal value and will only ever get a value of 0 the way it is now.
Loopi Looby
Registered User
Join date: 17 Jan 2007
Posts: 3
09-19-2008 10:40
or use llround?
Enkidu Recreant
Registered User
Join date: 27 Aug 2007
Posts: 28
09-23-2008 07:23
Thanks for the tips. Using a random number of 2 rather 1 sorted out the problem. (The initial one anyway.)

I then set up the rotation as llRotateTexture(PI, ALL_SIDES); to give a 180 degree turn (damn radians!)

Is there a command that tells the system to rotate by 0 (or 360) degrees?

Thanks
Ben Bacon
Registered User
Join date: 14 Jul 2005
Posts: 809
09-23-2008 07:48
yup

llRotateTexture(0.0, ALL_SIDES);