Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Random text issues

Kithro Luan
Registered User
Join date: 12 Apr 2006
Posts: 9
07-07-2006 18:31
Well,heres what I got so far:

------

float pick1;
integer pick2;

float ranTime;
randomtimer()
{
ranTime = llFrand(60);
}



TextPicker()
{


pick1 = llFrand(15);

if (pick1 > 5)

{
llSay(0, "Walmart Owns you!";);
}

if (pick1 < 5)

{

llSay(0, "Keep those prices rolling!";);

}
if (pick1 < 15)
{
llSay(0, "-snicker- One, Two; Walmarts coming for you. Three, four; You better shut the door... -evil grin-";);
};



}

default
{
state_entry()
{

randomtimer();
llSetTimerEvent(ranTime);
}

timer()
{
randomtimer();
TextPicker();



}
}


-----


My problem is, with more then two if statements is that I have issues, because It always says the third choice. This is the best script I can come up with for it, im still pretty new. But, is there a way I can fix the problem with the parameters? I mean, if I wanted to add more things to say that would be even more of an issue. Could someone please help me out here?
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
07-07-2006 19:09
all if's get tested during the event

if (1 == 1) llOwnerSay("1 = 1";);
if (2 == 2) llOwnerSay("2 = 2";);

output:
1 = 1
2 = 2

becuase both are true :)

use else if

if
else if
else if
else

lsl will test if first, if thats not true it will move down to else if, and so on, if a statement returns TRUE lsl will jump out of the if else loop without testing anything else and moves on like normal

also in vastly large chains or nested clauses else if will greatly speed up the script becuase it only tests untill it gets TRUE, vs testing each and every if statement in a 50 clause nest
Llauren Mandelbrot
Twenty-Four Weeks Old.
Join date: 26 Apr 2006
Posts: 665
07-08-2006 10:18
Try something like this?

CODE

float pick1;
integer pick2;
list Messages = [
"Walmart Owns you!",
"Keep those prices rolling!",
"-snicker- One, Two; Walmarts coming for you. Three, four; You better shut the door... -evil grin-"
]

float randomtimer()
{
return llFrand(60);
}

TextPicker()
{
llSay(0, llList2String(Messages, (integer)llFrand(llGetListLength(Messages))));
}

default
{
state_entry() {llSetTimerEvent(randomTimer());}
timer()
{
llSetTimerEvent(randomTimer());
TextPicker();
}
}
Caution: Not verified in LSL editor. Your milage may vary.
Kithro Luan
Registered User
Join date: 12 Apr 2006
Posts: 9
07-08-2006 11:13
I will check that out in a moment. I have edited my script with some else if statements, but I have ran into an issue.


///////

float pick1;


float ranTime;
randomtimer()
{
ranTime = llFrand(35);
}



TextPicker()
{


pick1 = llFrand(15);

if (pick1 = 1)

{
llSay(0, "Walmart Owns you!";);
}
else if (pick1 = 2)

{

llSay(0, "Keep those prices rolling!";);

}
else if (pick1 = 3)
{
llSay(0, "-snicker- One, Two; Walmarts coming for you. Three, four; You better shut the door... -evil grin-";);
}

else if ( pick1 = 4)

{

llSay(0, "Whats better then sex? Shopping at Walmart!";);

}


else if (pick1 = 5)

{

llSay(0, "Walmart makes people happy, why do you think I smile all the time?";);

}


else if (pick1 = 6)

{

llSay(0, "Man asks, what was before God? The answer, Walmart";);


}



else if (pick1 = 7)

{

llSay(0, "Where does Chuck Norris shop? Walmart of course!";);


}


else if (pick1 = 8)


{
llSay(0, "Did you know that not shopping at Walmart is illegal?";);


}


else

{
llSay(0, "Yes, I have met the Trojan man. To be honest, he didn't live up to what I thought he would be. Remember kids, the best to have safe sex is to shop at Walmart";);



}


}

default
{
state_entry()
{

randomtimer();
llSetTimerEvent(ranTime);
}

timer()
{
randomtimer();
TextPicker();



}
}



////////


It just keeps saying "Walmart owns you!" rather then any of the others. Have I done something wrong?


***Edit---

Llauren Mandelbrot, that scripts works very well. I am still fairly new to scripting so I got two things good from it. Learned of an event and got a way for my script to work. Thank you

----***


Though I would still like to know whats wrong my code, for future reference.
Jesse Malthus
OMG HAX!
Join date: 21 Apr 2006
Posts: 649
07-08-2006 12:45
you must use ==, with = it's always true and corrupts your value.
Llauren Mandelbrot
Twenty-Four Weeks Old.
Join date: 26 Apr 2006
Posts: 665
07-08-2006 13:02
From: Kithro Luan
I will check that out in a moment. I have edited my script with some else if statements, but I have ran into an issue.


///////

float pick1; //1, 2.2


float ranTime; //2.1, 3
randomtimer()
{
ranTime = llFrand(35); //3
}



TextPicker()
{
//2.2
pick1 = llFrand(15); //1

if (pick1 = 1)

{
llSay(0, "Walmart Owns you!";);
}
else if (pick1 = 2)

{

llSay(0, "Keep those prices rolling!";);

}
else if (pick1 = 3)
{
llSay(0, "-snicker- One, Two; Walmarts coming for you. Three, four; You better shut the door... -evil grin-";);
}

else if ( pick1 = 4)

{

llSay(0, "Whats better then sex? Shopping at Walmart!";);

}


else if (pick1 = 5)

{

llSay(0, "Walmart makes people happy, why do you think I smile all the time?";);

}


else if (pick1 = 6)

{

llSay(0, "Man asks, what was before God? The answer, Walmart";);


}



else if (pick1 = 7)

{

llSay(0, "Where does Chuck Norris shop? Walmart of course!";);


}


else if (pick1 = 8)


{
llSay(0, "Did you know that not shopping at Walmart is illegal?";);


}


else

{
llSay(0, "Yes, I have met the Trojan man. To be honest, he didn't live up to what I thought he would be. Remember kids, the best to have safe sex is to shop at Walmart";);



}


}

default
{
state_entry()
{

randomtimer();
llSetTimerEvent(ranTime);
}

timer()
{
randomtimer(); /3.1
TextPicker();



}
}



////////


It just keeps saying "Walmart owns you!" rather then any of the others. Have I done something wrong?


***Edit---

Llauren Mandelbrot, that scripts works very well. I am still fairly new to scripting so I got two things good from it. Learned of an event and got a way for my script to work. Thank you

----***


Though I would still like to know whats wrong my code, for future reference.
Several things, actually.
  1. You are comparing FLOATS against INTEGERS for EXACT EQUALITY. You need to declare pick1 as an integer and cast your llFrand(60) to an integer:
    1. integer pick1;
    1. pick1 = (integer)llFrand(60);

  2. You are using GLOBAL variables where LOCAL variables --or even NO variables!-- would to the job fine. Never use global variables that you do not need to use.
    1. Variabale float ranTime is not needed at all.
    2. Variable pick1 should be declared within the function that uses it.

  3. Function randomtimer() only sets a global variable, and one that is only used once. You need to USE the value that this sets. The best way would be to code a direct call to llSetTimerEvent(llFrand(35)) within the body of the function, and dispense with variable float ranTime entirely.
    1. In particular, using randomtimer() --as written-- in the timer() event does nothing useful.

I would not have picked your code apart like this, but you DID **ask** me to -- literally!

I hope you learned something useful from this.

Toodle-oo!