Sanity Karuna
Registered User
Join date: 24 Jun 2004
Posts: 20
|
08-07-2004 01:47
Hi, this is probably a simple answer. What I am trying to do is have one state pick a number out of 4 and then have the object say the number and then to go onto another state from each different number picked. For example you touch the object then it says "2" when you touch it again it will goto the next state This is all I could think up from reading other posts: but it doesn't work From: someone default { state_entry() { llSay(0, "Hello, Avatar!"  ; } touch_start(integer total_number) { if (llFrand(4) == 1 ) { llSay(0, "1"  ; } if (llFrand(4) == 2 ) { llSay(0, "2"  ; } if (llFrand(4) == 3 ) { llSay(0, "3"  ; } } } Thank you =)
|
Chris Byrne
Broccoli Chef
Join date: 21 Mar 2004
Posts: 57
|
08-07-2004 02:09
First, you were calling the Rand function on each comparison. Assign it to a variable once, then check that variable multiple times. float randf=llFrand(4.0); Now you have your FLOAT, e.g. 1.123958 " llFrand float llFrand(float mag); Returns a pseudo-random number between 0 and mag. " Then use llRound to get an integer integer rand=llRound(randf); then compare that... default { state_entry() {llSay(0, "Hello, Avatar!"  ;} touch_start(integer total_number) { float randf=llFrand(4.0); integer rand=llRound(randf); if (rand == 0) {llSay(0, "0"  ;} if (rand == 1 ) {llSay(0, "1"  ;} if (rand == 2 ) {llSay(0, "2"  ;} if (rand == 3 ) {llSay(0, "3"  ;} } }
|
Samhain Broom
Registered User
Join date: 1 Aug 2004
Posts: 298
|
08-10-2004 10:39
if you round the number, you may sometimes wind up with a number higher than the desired max. For example, a 4.8 would round to 5.
Use this method in stead to convert to an integer.
integer rand=(integer)randf;
(in stead of) integer rand=llRound(randf);
|
Wednesday Grimm
Ex Libris
Join date: 9 Jan 2003
Posts: 934
|
08-10-2004 10:57
Save a precious few lines of code, skip the rounding and say if (fRand < 1.0) {llSay(0, "0");} if (fRand < 2.0 ) {llSay(0, "1");} if (fRand < 3.0 ) {llSay(0, "2");} else {llSay(0, "3");}
_____________________
Sarcasm meter: 0 |-----------------------*-| 10 Rating: Awww Jeeze!
|
Tiger Crossing
The Prim Maker
Join date: 18 Aug 2003
Posts: 1,560
|
08-10-2004 11:07
You'll want else's on that, Wed... float num = llFrand( 4 ); if ( num < 1.0 ) llWhisper( 0, "First!" ); else if ( num < 2.0 ) llWhisper( 0, "Second!" ); else if ( num < 3.0 ) llWhisper( 0, "Third!" ); ... etc And the range of the returned value is [0,mag). This means that if mag is 4, llFrand will never return exactly 4, but it could return 0. It might get to 3.999999999, but never 4. And rounding won't work since anything less than .5 becomes 0 and from .5 to anything less than 1.5 becomes 1. So zero only gets half the probability of 1. 0,1,1,2,2,3,3,4 instead of 0,0,1,1,2,2,3,3
_____________________
~ Tiger Crossing ~ (Nonsanity)
|
Wednesday Grimm
Ex Libris
Join date: 9 Jan 2003
Posts: 934
|
08-10-2004 12:22
From: someone Originally posted by Tiger Crossing You'll want else's on that, Wed...
Oop, thanks.
_____________________
Sarcasm meter: 0 |-----------------------*-| 10 Rating: Awww Jeeze!
|
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
|
08-10-2004 16:08
integer a=llFloor(llFrand(4)); llSay(0,(string)a); if(a==0) {} else if(a==1) {} else if(a==2) {} else if(a==3) {}
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river. - Cyril Connolly
Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence. - James Nachtwey
|