|
Spartacus Wanderer
Joined: 23 Apr 2001 Posts: 53 Location: USA
|
Posted: Sat Mar 12, 2005 3:46 am
Accessing items in lists of lists |
I have a list of lists named LL that looks like this:
(1|2|3|4)|(5|6|7|8)|(9|10|11|12)|(13|14|15|16)
One of the help files suggested that its elements can be accessed using the following notation, and it can:
@LL.3.2 (gives 10, as expected)
Code: |
Of course this isn't good enough for me. Now I want to access it like this:
#loop 4 {
#var i {%i}
#loop 4 {
#var j {%%%i}
#echo @LL.@i.@j
}
} |
But it only displays the full list followed by the values in @i and @j. Is there a way to make these variables expand first so that the list is accessed appropriately? |
|
_________________ Spartacus
rm -rf .* |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Sat Mar 12, 2005 6:57 am |
You can't do it via dot notation, that has to be literal. You might try fiddling with %item() to see if you can get that to work, but other than that I can't really see any way to do what you want.
|
|
_________________ EDIT: I didn't like my old signature |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Sat Mar 12, 2005 3:17 pm |
This works perfectly with the current version of zMud.
Code: |
#var LL {(1|2|3|4)|(5|6|7|8)|(9|10|11|12)|(13|14|15|16)}
#loop 4 {
#loop 4 {
#echo @{LL.%i.%j}
}
} |
|
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
Spartacus Wanderer
Joined: 23 Apr 2001 Posts: 53 Location: USA
|
Posted: Tue Mar 15, 2005 4:32 pm |
Is %j the same as %%%i? I didn't find %j in the help files for predefined variables or #LOOP. If %j works for the second nested loop, will %k work for the third? %l for the fourth? How far is this notation supported?
|
|
_________________ Spartacus
rm -rf .* |
|
|
|
mr_kent Enchanter
Joined: 10 Oct 2000 Posts: 698
|
Posted: Tue Mar 15, 2005 5:55 pm |
6.56 9-Apr-03 (BETA version)
%i, %j, %k, etc loop variables are now expanded EARLY, similar to %1..%99 variables. This means than when using nested loops, you MUST use %j instead of %i to refer to the innermost loop. This could break existing scripts that were not using %i and %j correctly. Additional variables such as %k, %l, %m... can be used for additional nested loops. The %repeatnum variable is still expanded late as before and can be used to reference the innermost loop if backwards compatibility is needed.
%room functions no longer sometimes use the wrong room info |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Tue Mar 15, 2005 11:18 pm |
It will be better documented when I finally finish updating the help. I suppose it will run at least until z, but why you would need that much is beyond me. In my programming experience, I can't recall ever having more then 5 nested loops.
|
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
Spartacus Wanderer
Joined: 23 Apr 2001 Posts: 53 Location: USA
|
Posted: Wed Mar 16, 2005 4:34 pm |
Well, I tested it through 10 nested loops and it works - though my personal feeling is that more than 3 and there's probably a better, smarter, and faster way to do it.
Thanks for the info! I'm looking forward to seeing the updated help files! |
|
_________________ Spartacus
rm -rf .* |
|
|
|
|
|