Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Spin the Bottle script problems.

Allen Harrington
Registered User
Join date: 14 Jul 2005
Posts: 60
10-17-2005 13:25
I have a friend who has asked if I could make a “Spin The Bottle” object. I’ve looked over the scripting commands available and I’m not sure if the needed action can be done. The idea is to have an object you would touch to start the spin. The spin would start out at a rate of 4 or 5 revolutions per second and slow down to a stop in about ten seconds. Also it would have to stop at random positions. Can this be done? I’ve tried using the llSetRot along with the llFrand but it didn’t work right. For one, I think I’m not using the llFrand right. I seem to be getting the same number each time. The wiki example for this command is not clear to me. One more thing, once you have declared a variable and set its initial value, how do you set it to a different value?

Or if someone wants to write the script for me I will pay 300 $L for it. (Will pay more if I'm given permission to copy it to be used in more than one object.)
_____________________
Photo Gallery at www.tigerzero.com
Anthrocon 2004 & 2005 photos at www.tigerzero.com
Dianne Mechanique
Back from the Dead
Join date: 28 Mar 2005
Posts: 2,648
10-17-2005 13:29
From: Allen Harrington
I have a friend who has asked if I could make a “Spin The Bottle” object. I’ve looked over the scripting commands available and I’m not sure if the needed action can be done. The idea is to have an object you would touch to start the spin. The spin would start out at a rate of 4 or 5 revolutions per second and slow down to a stop in about ten seconds. Also it would have to stop at random positions. Can this be done? I’ve tried using the llSetRot along with the llFrand but it didn’t work right. For one, I think I’m not using the llFrand right. I seem to be getting the same number each time. The wiki example for this command is not clear to me. One more thing, once you have declared a variable and set its initial value, how do you set it to a different value?

Or if someone wants to write the script for me I will pay 300 $L for it. (Will pay more if I'm given permission to copy it to be used in more than one object.)
I dont have much comment as its beyond me too. I think if yu havent already done it, resetting the script each time might make a diff frand come up? possibly anyway.

I am mostly posting cause I want one of these! ;)

If you ever get it made I will buy one for sure.
_____________________
.
black
art furniture & classic clothing
===================
Black in Neufreistadt
Black @ ONE
Black @ www.SLBoutique.com


.
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
10-17-2005 13:47
Should be doable, I think. Try using llFrand() to generate a random number, then use that number to apply a rotational impulse to the bottle. The object will need to be physical for this to work, and you'll probably have to clamp down a MoveToTarget to ensure that the bottle doesn't start rolling away as it's spinning. Then you could use a timer and figure out the end rotation, or stop the movement after a timer expires, or something like that. That should get you a bottle that slows down and stops at a different position each time.

From: someone
One more thing, once you have declared a variable and set its initial value, how do you set it to a different value?


Initial declaration and assignment:

CODE
integer variableName = initialValue; // Or string or vector or whatever


Re-assign a new value:

CODE
variableName = newValue;


Use the same variable name, and don't specify a type this time because you've already declared the variable in the previous line, this one's just assigning a new value.
Kurt Zidane
Just Human
Join date: 1 Apr 2004
Posts: 636
10-17-2005 18:14
if it was me. I would forgo the effects, and script the logic out.

sudo:
On mouse down, set toucher id to the tuch, set timer to one minute, roate random, scan for avatars.

on find avatar, set key to avatar's key. if key is not on key list, then add key to key list.

on timer
set timer to zero
get key list length, if list length is greater -1 then, set number to random number between 0 and (list length - 1)
set target to list2key( key list, random number)
point object to target
llSay(0, Key2Name(touch id) + " spins the bottle, and it points to " + Key2Name(target) + "." );
clear touch id
clear key list
Lit Noir
Arrant Knave
Join date: 3 Jan 2004
Posts: 260
10-18-2005 11:18
Well, this may be a "duh" kind of answer (in that you already know this), but how are you using the frand call? To get back an angle of rotation or an avatar "number" (from a list of avs after a sensor sweep)? If the former, remember that SetRot is based on radians and not degrees. If the latter, well, not likely you would be having this problem but you have to make some minor math tweaks to balance the probablities to be equal for all avs (rounding a float to an integer will halve the chance for the first and last avs to get called versus all the others.

I would use a sensor and find put the avs and their respective angles (after a little trig) in a list, and use frand to determine the list index and point (after a few rotations). If you want folks to have humorous arguments over who the closest target av is, then screw the sensor and just pick a random radian number.

SetRot will do the job, though it might take some tweaking to get the rotation effect to look smooth (0.2 second delay or some such, circumventable). Texture rotations could be smoother, but that requires some texture work and you'll lack the visual depth for the object.