Question about formatting a command
|
Samhain Broom
Registered User
Join date: 1 Aug 2004
Posts: 298
|
11-01-2004 12:41
Can you expect a command like:
llList2Integer(someList, (x+y%5))
to work in a for loop like:
llList2Integer(someList, 1) llList2Integer(someList, 2) llList2Integer(someList, 3) llList2Integer(someList, 4)
In otherwords, will the (x+y%5) be evaluated or will it just be an error?
I'm guessing that I have to add another value so that I can just put that variable in the equasion:
z=(x+y%5)
then
llList2Integer(someList, z)
_____________________
rm -rf /bin/ladden #beware of geeks bearing grifts
|
Water Rogers
Registered User
Join date: 1 May 2003
Posts: 286
|
11-01-2004 13:05
As long as it evaluates to an integer, then you should be fine. edit: gave this code a whirl in game real quick... dunno if it's exactly what you were talking about... but here's the results: list someList = ["1", "2", "3", "4", "5"]; integer x = 1; integer y = 1;
default { state_entry() { integer someInteger = llList2Integer(someList, (x+y%5)); llSay(0, "someList = " + llList2CSV(someList)); llSay(0, "someInteger = " + (string)someInteger); } }
//////////////////////////////////////////////////////// // Outputs ////////////////////////////////////////////////////////
Object: someList = 1, 2, 3, 4, 5 Object: someInteger = 3
_____________________
From: Philip Linden For the more technically minded - the problem is actually NOT the asset server (or 'asshat' as you prefer to affectionately call it herein).
|
Wednesday Grimm
Ex Libris
Join date: 9 Jan 2003
Posts: 934
|
11-01-2004 13:36
yes, even something zany like llList2String(lMyList, llList2Integer(lMyList, x*2)); would work. Variable are ALWAYS  interperted when they're used, and arguments to a function are interpreted (resolved, finalized, calculated, whatevered) just before the function is called.  almost always, probably, the LSL compiler might do some optimizations, but in any case, it's safe to assume always.
_____________________
Sarcasm meter: 0 |-----------------------*-| 10 Rating: Awww Jeeze!
|
Samhain Broom
Registered User
Join date: 1 Aug 2004
Posts: 298
|
11-03-2004 08:30
That helps a LOT Wednesday! I wanted to have a list of integers something like: myList=[1143, 2143, 3143, 4143] I want to randomly select an integer from this list (let's say for example the second item in the list) Then do a "for loop" that always does 4 iterations. So, if I start with 1, I want the for loop to count thus: 1,2,3,0 then stop. If it starts on the 3rd, it should count: 2,3,0,1 and so on. Assuming that integer x; integer y; integer z; is done somewhere and I call a function with a random value "y" so if I do: for (x=0; x>3;x++) { z=llList2Integer(myList, (x+y%5)); //do something with "z" }
Now, when I start this loop, depending on what y equals, I will achieve the above sequences, and z will be the integers from the list right?
_____________________
rm -rf /bin/ladden #beware of geeks bearing grifts
|
Wednesday Grimm
Ex Libris
Join date: 9 Jan 2003
Posts: 934
|
11-03-2004 11:02
From: Samhain Broom for (x=0; x>3;x++) { z=llList2Integer(myList, (x+y%5)); //do something with "z" }
The concept is correct, but you probably want: z=llList2Integer(myList, ((x+y)%4)); // extra brackets and 4 instead of 5
4 not 5 because 4%4 = 0 extra brackets because % is "stronger" than + (I think) so without brackets you would get y%4 + x
_____________________
Sarcasm meter: 0 |-----------------------*-| 10 Rating: Awww Jeeze!
|
Samhain Broom
Registered User
Join date: 1 Aug 2004
Posts: 298
|
11-03-2004 13:15
I also noticed I need to change the for loop math there... it should say for (x=0; x<3; x++) { bla }
_____________________
rm -rf /bin/ladden #beware of geeks bearing grifts
|
Samhain Broom
Registered User
Join date: 1 Aug 2004
Posts: 298
|
11-04-2004 18:24
ok for proof of concept... here was the final test that I used to prove that the snippet worked. I am providing this for discussion in case someone learning wants to know more. Thanks Wednesday for the assistance. retest() { float x = llFrand(3 - 0) + 0; integer y = (integer)x; list playerList=[1143, 2143, 3143, 4143]; //a list of integers llWhisper(0, "x = " +(string)x); llWhisper(0, "y = " +(string)y); integer i; for (i = 0; i <4; i++) { integer cardID = llList2Integer(playerList, ((i+y)%4)); llWhisper(0, "cardID = " +(string)cardID); } }
default { state_entry() { llWhisper(0, "Touch to restart"); }
touch_start(integer total_number) { retest(); } }
I provided some extra 'llWhispers()' as test points to see what the values were... I will clean those up in the real script. The following is an example output: Object whispers: x = 1.017203 Object whispers: y = 1 Object whispers: cardID = 2143 Object whispers: cardID = 3143 Object whispers: cardID = 4143 Object whispers: cardID = 1143
so the floating point "x" was equal to 1 (something) then cleaned up into an integer into "y" for later use in the "for loop" I was sucessful in printing my list of integers. Yeah! Thanks again!
_____________________
rm -rf /bin/ladden #beware of geeks bearing grifts
|