|
sda Wanderer
Joined: 18 Apr 2001 Posts: 55 Location: United Kingdom
|
Posted: Thu Jul 11, 2002 10:58 pm
Nested loops |
If you nest #LOOP commands, I know you can use %i for the loop count, but what if they are nested?
For example, what if I want:
#LOOP 1,10 {#LOOP 10,1 {#SH %i,%i}}
Obviously I can't have %i twice, and I've tried %j, %k etc., but no success.
Thanks,
Steve :) |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Thu Jul 11, 2002 11:37 pm |
quote:
If you nest #LOOP commands, I know you can use %i for the loop count, but what if they are nested?
For example, what if I want:
#LOOP 1,10 {#LOOP 10,1 {#SH %i,%i}}
Obviously I can't have %i twice, and I've tried %j, %k etc., but no success.
Thanks,
Steve :)
ZMud has no native support for nested loop counters, so you'll need to save the outer loop's iteration value before you enter the inner loop. Not sure if the %i's revert back to the proper value once the inner loop is exited, so you might have to completely maintain one of the counter variables yourself.
li'l shmoe of Dragon's Gate MUD |
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Thu Jul 11, 2002 11:39 pm |
Yes, they do revert back. So, for example, this should work:
#LOOP 1,10 {#VAR outsideCount %1;#LOOP 10,1 {#SH @outsideCount,%i}}
Kjata |
|
|
|
GrimofDC Beginner
Joined: 14 Jul 2002 Posts: 18
|
Posted: Sun Jul 14, 2002 1:21 am |
quote:
Yes, they do revert back. So, for example, this should work:
#LOOP 1,10 {#VAR outsideCount %1;#LOOP 10,1 {#SH @outsideCount,%i}}
Kjata
Hi,
I'm new here so this may be incorrect, and Kjata your posts have been very informative to me, however I had to change %1 to %i to get to the loops to work correctly:
#LOOP 1,10 {#VAR outsideCount %i;#LOOP 10,1 {#SH @outsideCount,%i}}
I'm also interested in how to go about using parameters within a loop. For example:
#TR {Str: (%d) (%d) (%d) (%d) (%d)} / The mud rolls five different rolls at once.
#VAR StrStat %1
#Loo 2,5 { #VAR StrStat %addItem(%%i, @StrStat) / This doesn't seem to work
Here is real mud output:
Choose from any of the following groups of abilities...
Group: 1 2 3 4 5
Str: 13 17 15 13 13
Int: 15 17 13 12 16
Wis: 15 14 17 12 12
Dex: 16 17 14 14 12
Con: 12 15 11 17 13
Choose a group <1-5>, or press return to reroll -->
Thanks,
Grim |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Sun Jul 14, 2002 1:31 am |
Yes, Kjata seems to let more of these very minor errors slip through the editing process. They're always very minor details, but they say the Devil's in the details...
I think it's a good thing, though, because it causes people to actually look at the code and figure out what it's doing (if they don't know already). If they can follow through the code logic, then it stands to reason the problem is obviously a minor detail somewhere and they won't have to worry about whether there's faulty logic at play here.
li'l shmoe of Dragon's Gate MUD |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Sun Jul 14, 2002 2:13 am |
You could try this, but i dont think it will work either:
#Loo 2,5 { #VAR StrStat %addItem(%{%i}, @StrStat)
A more expedient solution that will work...
#TR {^Str: (*)$} {#VAR StrStat {%replace("%1"," ","|")}} |
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Sun Jul 14, 2002 2:23 am |
Hehe, oops.
Kjata |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Sun Jul 14, 2002 4:26 pm |
GrimofDC
If you need help with that autoroller start a new topic. Along with the MUD output, be sure to include what would constitute an acceptable roll and what action you want to take when you have one. Since you might get more than one acceptable roll at the same time, you might want to stop and choose between them instead of just sending a number to the MUD.
LightBulb
Senior Member |
|
|
|
GrimofDC Beginner
Joined: 14 Jul 2002 Posts: 18
|
Posted: Sun Jul 14, 2002 10:04 pm |
Re: LightBulb
I'm too shy to start my own topic and most of what I have to post applies to the orginal loop topic. Also I managed solve my previously posted problem. Here's the loop:
#loo 1,5 {#var testvar %i;#loo 1,5 {#show %item(@{Group@testvar}, %i)}}
Where @testvar is the outside loop counter
And I have five variables saving the values for Str, Int, Wis, Dex, and Con. They are arrays known as @Group1, @Group2, @Group3, @Group4, and @Group5
Here are the @GroupX values if someone wants to plug them in and test the loop.
#var Group1 012|012|013|014|012
#var Group2 016|011|014|012|011
#var Group3 015|014|015|015|009
#var Group4 010|013|011|013|013
#var Group5 010|013|011|014|015
To finish my autoroller I did not need to use this nested loop, but I posted "sda's" modified loop here incase anyone needs help looping through set of common variable names and is having a problem "attaching" the %i value. I also need to give praise to Kjata for help formating those numbers correctly for sorting. Unfortunately I cannot remember the posts link.
~Grim |
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|