|
Artemis Cain
Take it or Leave it
Join date: 11 Apr 2005
Posts: 116
|
05-16-2006 07:41
I am trying to use an if/else loop to make sure that a number (chosen randomly) is only used once in a given set of numbers. for some reason, I am not able to compile this. My code is probably crap, but I have commented with my actual intent for the functions.
integer giUsed; integer i; integer tex; string chosen_texture; list textures = ["1l","2l","3l","4l","5l","6l","7l","8l","9l","10l","11l", "12l","13l","14l","15l","16l","17l","18l","19l","20l","21l","22l","23l","24l","25l","26l"]; default { state_entry() { for(i=0; i<25; ++i) { giUsed=FALSE; //Marking all numbers as not used, so that I can reset it //with an llResetScript command } }
link_message( integer sender, integer num, string message, key id ) { // I just received a texture request from someone! if( message == "tex_req" ) { // Basically, what I am trying to do here is check to see if the number is used, // If it is not used, I want to use it and mark "giUsed" as true // If it is used, I want it to choose another random, until it finds one that isn't //used @again; tex = llFloor( llFrand( i ) ); if (! giUsed) { chosen_texture = llList2String(textures, tex); giUsed = TRUE; llMessageLinked( sender, 0, "tex_req", chosen_texture ) ; }
else { jump again; }
Any help would be greatly appreciated! -Art
|
|
Nick Shatner
Isn't a game
Join date: 11 Jul 2005
Posts: 39
|
05-16-2006 07:51
IM'ing you in world 
|
|
Nexus Nash
Undercover Linden
Join date: 18 Dec 2002
Posts: 1,084
|
05-16-2006 08:02
Couple things... 1. Lose the jump 2. in your list store your numbers as int (ie lose the " "  3. to find your number do this... if(llListFindList(textures,[?numbertofind?]) == -1) { number wasn't found add it } else {//number was found make another one } 4. your llFrand... i'll be picky but it's better practice using llFrand(1.0) * i then llFrand(i) I have a bit of time, i'll write you a function. I can only access the forums so it 'might' not compile  //i'm taking for granted that 0 is not an 'number' integer getNumber(list lData,integer lMaxInt) {
//just a safety so it doesn't go infinite loop if(llGetListLength(lData) > lMaxInt) return FALSE;
integer num = llCeil((llFrand(1.0) * (float)lMaxInt) + 0.01); if(llListFindList(lData,[num]) == -1) return num; else getNumber(lData,lMaxInt);
}
|
|
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
|
05-16-2006 13:34
From: Nexus Nash 4. your llFrand... i'll be picky but it's better practice using llFrand(1.0) * i then llFrand(i) Why?
|
|
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
|
05-16-2006 14:07
From: Artemis Cain I am trying to use an if/else loop to make sure that a number (chosen randomly) is only used once in a given set of numbers. #1 put your numbers in the list #2 llListRandomize()#3 walk through list from beginning to end, reading the numbers as they come should do about the same thing? ^^;;
|