random number guesser
|
|
Aniam Ingmann
llOwnage(float pwnage);
Join date: 22 Oct 2005
Posts: 206
|
11-15-2007 04:18
I'm trying to set up a simple llDialog based random number guesser, just for fun.. but i don't know what to do because everything works correctly except for that the llDialog doesn't allow itself to read a list of integers. It only accepts strings, but i don't know how to make [0,1,2,3,4,5,6,7,8,9,10]... etc a string so that it can be usable...
_____________________
From: someone Don't worry, Aniam is here! - Noob
|
|
Debbie Trilling
Our Lady of Peenemünde
Join date: 17 Oct 2006
Posts: 434
|
11-15-2007 04:34
Hi Simplest way is to make the list entries themselves into strings by adding quotes, ie: ["0","1","2","3","4","5","6","7","8","9","10"]... and then typecasting the selection back into an integer when it comes to using it, eg: (integer)"10" There are numerous (and far better) other solutions, but this explains the bare essence of what I think you are asking 
|
|
Siro Mfume
XD
Join date: 5 Aug 2004
Posts: 747
|
11-15-2007 05:30
If you're generating new sets of random numbers each time, you might want to just typecast the integers as strings when you use llDialog. Like [(string)intA, (string)intB, (string)intC]
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
11-15-2007 07:17
Put all of the numbers into a list. Use list length as the number in llFrand and change the output from a float to an integer. Then just return the results of llList2String.
Either that or you can just use (integer)llFrand(20.0) for example to return an integer between 0 & 20. Then typecast the integer as a string.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
|
Debbie Trilling
Our Lady of Peenemünde
Join date: 17 Oct 2006
Posts: 434
|
11-15-2007 07:55
Siro is ofc absolutely right, if it is the menu buttons themselves that they to be random numbers (rather than using the numbers one to ten upon which to base the generation of a random number, as I think I incorrectly thought last time I looked) then you will need to use typecast integer variables. The following example generates twelve randomly generated numbers bewteen 1 and 100 on touch, sorts them into ascending order and these displays these numbers as menu buttons. Clicking a menu button will say that value in chat. 
//declare integers integer CommChannel = 10; integer ListenChannel = 10; integer RanNum1; integer RanNum2; integer RanNum3; integer RanNum4; integer RanNum5; integer RanNum6; integer RanNum7; integer RanNum8; integer RanNum9; integer RanNum10; integer RanNum11; integer RanNum12;
//http://rpgstats.com/wiki/index.php?title=LlFrand integer RandInt(integer lower, integer higher) { integer Range = higher - lower; integer Result = llFloor(llFrand(Range + 1)) + lower; return Result; }
default { state_entry() { }
touch_start(integer total_number) { //generate random obscure listen channel number CommChannel = (0 - llFloor(llFrand(20000))); //set up listen channel ListenChannel = llListen(CommChannel, "", "", "");
//populate integers RanNum1 = RandInt(1,100); RanNum2 = RandInt(1,100); RanNum3 = RandInt(1,100); RanNum4 = RandInt(1,100); RanNum5 = RandInt(1,100); RanNum6 = RandInt(1,100); RanNum7 = RandInt(1,100); RanNum8 = RandInt(1,100); RanNum9 = RandInt(1,100); RanNum10 = RandInt(1,100); RanNum11 = RandInt(1,100); RanNum12 = RandInt(1,100);
//sort & populate menu list list MenuItems = llListSort([(string)RanNum1,(string)RanNum2,(string)RanNum3,(string)RanNum4,(string)RanNum5,(string)RanNum6,(string)RanNum5,(string)RanNum8,(string)RanNum9,(string)RanNum10,(string)RanNum11,(string)RanNum12],1,TRUE);
//raise dialog box llDialog(llGetOwner(), "Select one of the following randomly generated numbers:",MenuItems,CommChannel);
} //listen listen(integer channel, string name, key id, string message) { //process llSay(0, "You selected random number " + message); //close listen llListenRemove(ListenChannel); } }
|
|
Aniam Ingmann
llOwnage(float pwnage);
Join date: 22 Oct 2005
Posts: 206
|
11-15-2007 11:19
Wow! Thanks a bunch! All your posts helped me a bunch. I've always been having problems involving randomizing inside LSL, and this really opened up some possiblities for me  Thanks.
_____________________
From: someone Don't worry, Aniam is here! - Noob
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
11-15-2007 16:51
Just goofing around: list rand_list; list menu_list; integer n;
default { state_entry() { for(n=1;n<100;n++) { rand_list += (rand_list=[]) + rand_list + [(string)n]; } }
touch_start(integer total_number) { rand_list = llListRandomize(rand_list,1); menu_list = llListSort((llList2List(rand_list,0,11)),1,1); llDialog(llDetectedKey(0),"12 random numbers 1 to 100",menu_list,-41684186); } }
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
11-15-2007 17:13
Still goofing off: list rand_list; integer n;
default { touch_start(integer total_number) { rand_list = []; for(n=0;n<12;n++) { rand_list += (rand_list=[]) + rand_list + [(string)((integer)(llFrand(99)+ 1))]; } rand_list = llListSort(rand_list,1,1); llDialog(llDetectedKey(0),"12 random numbers 1 to 100",rand_list,-41684186); } }
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|