Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

What am I doing Wronge?

perttu Kitty
I was here?
Join date: 17 Dec 2004
Posts: 23
05-19-2005 21:34
i have a script to say different thing every time someone touches an object but for some reason it only plays the second quote... What am i doing wronge?

CODE

default
{
touch_start(integer total_number)
{
float random_number = llFrand(21);
if (random_number > 20)
{
llSay(0, "EEP! Not The Tail!");
}
else if (random_number > 19 <= 20)
{
llSay(0, "/me starts laughing: Ohhh... Eeee... That Tickles!!!");
}
else if (random_number > 18 <= 19)
{
llSay(0, "Meep That tickles!");
}
else if (random_number > 17 <= 18)
{
llSay(0, "/me purs and moans: You knbow you have magic hands right?");
}
else if (random_number > 16 <= 17)
{
llSay(0, "OH Don't Stop!");
}
else if (random_number > 15 <= 16)
{
llSay(0, "/me purs and moans.");
}
else if (random_number > 14 <= 15)
{
llSay(0, "I love it when you touch me like that.");
}
else if (random_number > 13 <= 14)
{
llSay(0, "/me shutters in pleasure: Mmmm...");
}
else if (random_number > 12 <= 13)
{
llSay(0, "/me hickups.");
}
else if (random_number > 11 <= 12)
{
llSay(0, "/me sneazes.");
}
else if (random_number > 10 <= 11)
{
llSay(0, "/me cries: OUCH! >.<");
}
else if (random_number > 9 <= 10)
{
llSay(0, "Monkies!");
}
else if (random_number > 8 <= 9)
{
llSay(0, "Meep! Who was that?!");
}
else if (random_number > 7 <= 8)
{
llSay(0, "Pirates!");
}
else if (random_number > 6 <= 7)
{
llSay(0, "/me squeaks ang giggles: That tickles");
}
else if (random_number > 5 <= 6)
{
llSay(0, "/me giggles: havving fun? :P");
}
else if (random_number > 4 <= 5)
{
llSay(0, "Oohhh... don't stop!");
}
else if (random_number > 3 <= 4)
{
llSay(0, "Not So Hard!");
}
else if (random_number > 2 <= 3)
{
llSay(0, "/me purrrs: That feels soooo good");
}
else if (random_number > 1 <= 2)
{
llSay(0, "/me squeaks: Yes It's a tail");
}
}
}

_____________________
There's enough hatered in the world we don't need any on Second Life.
Pete Fats
Geek
Join date: 18 Apr 2003
Posts: 648
05-19-2005 22:02
Long story short, your if statements are missing &'s.

There is a much faster way though to accomplish what you are trying to do. Try this instead:

CODE
list saytext = ["quote1","quote2","quote3","quote4"];

default
{
touch_start(integer num)
{
llSay(0, llList2String(saytext, llFloor(llFrand(llGetListLength(saytext)))));
}
}


*written at work, but it should be correct.
_____________________
Douglas Callahan
Fresh Prince Of SL
Join date: 2 Jul 2004
Posts: 349
An Explanation
05-19-2005 22:31
definately use petes way or mine. For learning sake, I'll explain what you're doing wrong, as that was the title of this thread. :p

Okay, so you have a bunch of else if () statements that have

CODE
else if( randomnumber < 21 >= 19 )


, or something like this. If you want to test if the number is less than 21 AND greater than 19, you would have to use this way:

CODE
else if( randomnumer < 21 && randomnumer >= 19 )


notice the two && symbols, make sure you use two, as one means something different.

Also, if you were going to do this, a much easier way would be to set the random number to be an integer (not a float, as to eliminate decimals). If you do this, then you could simply check if the number equals 20, like so:

CODE
integer randomnumber = (integer) llFrand(21);
if ( randomnumber == 20 )
{
}


Again, notice the two == signs, this is extremely important, if you forget one of these, your script will be messed entirely.

One more thing on your method, llFrand() goes up to but does not include the number in the parentheses, so if you need numbers to go from 0,1,2,...,21, then use llFrand(22).

Now, Pete's method is by far a better and cleaner way to go. What he did was put all of you quotes into a list and use llFrand() to find a random one. I would prefer a different method:

CODE

list quotes = ["","",""]; //Put your quotes inbetween the quotation marks and add more for however many you need, max is 70 something though.

default
{
touch_start(integer start_params)
{
string quote = llList2String(llListRandomize(quotes,0)); //Notice that the string is called quote, while the list is called quotes, don't mix these up, change one if you need. Just because something is a different type (ie integer or string or list), doesn't mean it can have the same name.
llSay(0,quote);
}
}

This is different from pete's in that it does the randomizing via llListRandomize, instead of llFrand().

Hope this helps ;)

-Doug

P.S. Wrong has no "e" at the end of it :p
_____________________
Other than that, Mrs. Lincoln, how was the play?
Pete Fats
Geek
Join date: 18 Apr 2003
Posts: 648
05-19-2005 22:44
Good catch on the llListRandomize() call Doug. I forgot about that one.

Also thanks for typing out what was actually wrong. I am a man of few words, and I'm sure Pert will appricate your help. :)

One quick edit for you though, I think this line will not compile:

string quote = llList2String(llListRandomize(quotes,0));

should be:

string quote = llList2String(llListRandomize(quotes,0),0);
_____________________
Douglas Callahan
Fresh Prince Of SL
Join date: 2 Jul 2004
Posts: 349
05-19-2005 22:57
ooooh, thanks pete. Don't worry about explaining. Some people prefer just the answer not the process anyway.

BTW, your avatar for the forums kept my attention for about 6 minutes. Pretty awesome. :D
_____________________
Other than that, Mrs. Lincoln, how was the play?
Luke Ramona
Registered User
Join date: 3 Apr 2005
Posts: 32
05-20-2005 03:10
The first few lines of your code:

CODE

default
{
touch_start(integer total_number)
{
// Create a new random number from 1.0 to 21.0
// i.e. any number with up to 6 leading zeroes within that range
// e.g. 8.437281 or 15.029381 are both possible numbers in that range
// As has been suggested, it would be much better to use an integer here.
// Note the + 1 at the end, because most calculations start at 0 and count up
// from there, so there is a whole number between 0 and 1.
// 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 = 20 numerals
// To get 1 to 21, you need to start with 1 rather than 0, so you need a + 1
float random_number = llFrand(21) + 1; // between 1 and 21

// This IF statement would never have been true before because WITHOUT the
// + 1 on the end of the llFrand(21) statement, the value never goes over 20
if (random_number > 20)
{
llSay(0, "EEP! Not The Tail!");
}

// You can only perform one comparison at a time. To perform more than
// one in the same IF statement, you need to separate than with logical
// operators. In this case you want to know if the random number is:
// "greather than 19" AND "less than or equal to 20"
else if (random_number > 19 & random_number <= 20)
{
llSay(0, "/me starts laughing: Ohhh... Eeee... That Tickles!!!");
}
}
}



and so on.. rather than giving you an entirely new bit of code, here is what your existing code should have looked like.

Now you should really use the List method as shown by Pete because it means a lot less coding and is generally more efficient for compiling and exexcution.
Luke Ramona
Registered User
Join date: 3 Apr 2005
Posts: 32
05-20-2005 03:15
From: Douglas Callahan

CODE
else if( randomnumer < 21 && randomnumer >= 19 )


notice the two && symbols, make sure you use two, as one means something different.


According to the LSL guide, the && is used for TRUE/FALSE comparisons and the & is used for bitwise comparisons. Wouldn't it be the single ampersand (&;) for this case? I would have used a single ampersand, though I am new to LSL itself.
Zalandria Zaius
Registered User
Join date: 17 Jan 2004
Posts: 277
..
05-20-2005 07:10
You are asking for a true or false.. the && is used to make sure both are true..if only one is true it will return false to the if statement and skip to the next one.

if statements are always looking for a TRUE or FALSE
perttu Kitty
I was here?
Join date: 17 Dec 2004
Posts: 23
05-20-2005 09:17
Wow, i didn't think to get that many responces, you guys are awsome ^.^ I'm goin to go on and try that now. and hopefully before the hour is up i'll have a wicked cool talking tail ^.^


[edit]
Eeeeee!!! It Worked!! ANd since i don't know where you are on 2L so i can rate you all posotively i'm goin to give you a bunch of $L instead. And i know i don't have to but i will anyways cause i want to ^.^
[/edit]
_____________________
There's enough hatered in the world we don't need any on Second Life.
Keknehv Psaltery
Hacker
Join date: 11 Apr 2005
Posts: 1,185
05-20-2005 21:08
From: Luke Ramona
According to the LSL guide, the && is used for TRUE/FALSE comparisons and the & is used for bitwise comparisons. Wouldn't it be the single ampersand (&;) for this case? I would have used a single ampersand, though I am new to LSL itself.


That would be incorrect...

The && means that if both statements are true, it will return true. Here's an input-output table, or "truth table"

(1 is true, 0 is false)

CODE

Input: 1 2|Output
0 0|0
0 1|0
1 0|0
1 1|1


The & basically does an OR statement on every bit of the two values... Here are two examples to provide understanding:

CODE

1010
&0110
1110

~~~~~~

0010
&1000
1010


So, when you use the & operator on two true or false values, it is truly equivalent to an | (OR) operator. If you don't understand that, don't worry.

Perttu, these forums are roamed by people who are very willing to help. Post a message any time, no matter how simple or complex the problem is.

Enjoy your new tail :D
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
05-20-2005 23:02
Since they all have equal probability of coming up this makes the coding much easier.

CODE

list sayings =[ "EEP! Not The Tail!",
"/me starts laughing: Ohhh... Eeee... That Tickles!!!",
"Meep That tickles!",
"/me purs and moans: You knbow you have magic hands right?",
"OH Don't Stop!",
"/me purs and moans.",
"I love it when you touch me like that.",
"/me shutters in pleasure: Mmmm...",
"/me hickups.",
"/me sneazes.",
"/me cries: OUCH! >.<",
"Monkies!",
"Meep! Who was that?!",
"Pirates!",
"/me squeaks ang giggles: That tickles",
"/me giggles: havving fun? :P","Oohhh... don't stop!",
"Not So Hard!",
"/me purrrs: That feels soooo good",
"/me squeaks: Yes It's a tail"];

default
{
touch_start(integer a)
{
a = llGetListLength(sayings);
integer b = (integer)llFrand(4*a);
llSay(0, llList2String(sayings, b%a));
}
}
_____________________
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