Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
megamog75
Enchanter


Joined: 20 Nov 2002
Posts: 627
Location: USA

PostPosted: Mon Mar 31, 2014 3:19 am   

Loop and repeat or forall
 
Have been working on this for about two days now maybe someone can help.

This is what I want it to do:

loop through a string list var if any number is not a 1 then {yes} {no}, Where NO is #repeat 3 {#SH %i} now actuall "3" can be any number.
I have YES worked out
This is what I have and what I want in the end.

Code:

#Var String 2|1|6|3|1|5|12|2
#Forall @String {#If (%i = 1) {yes} {#Repeat %i {#sh hi_%i}}}

Should output for the first item in the @string
hi_1
hi_2


But it doesn't, what I get is:
hi_1
hi_1


Any thoughts or suggestions?
_________________
megamog75 Smile
I will do this.Nothing in my life matters except this.No moment in my life exists except this moment.I am born in this moment, and if I fail, I will die in this moment. Raistlin Majere

Last edited by megamog75 on Mon Mar 31, 2014 6:25 am; edited 1 time in total
Reply with quote
hadar
Apprentice


Joined: 30 Aug 2009
Posts: 198
Location: my apt, in california

PostPosted: Mon Mar 31, 2014 4:25 am   
 
works for me when i tested
Code:

hi_2
hi_2
yes
hi_6
hi_6
hi_6
hi_6
hi_6
hi_6
hi_3
hi_3
hi_3
yes
hi_5
hi_5
hi_5
hi_5
hi_5
hi_12
hi_12
hi_12
hi_12
hi_12
hi_12
hi_12
hi_12
hi_12
hi_12
hi_12
hi_12
hi_2
hi_2


unless you wanted other results?
_________________
if you build it they will come, assuming that they have not already come to build it
Aardwolf Bootcamp
My youtube channel
Reply with quote
megamog75
Enchanter


Joined: 20 Nov 2002
Posts: 627
Location: USA

PostPosted: Mon Mar 31, 2014 6:24 am   
 
Thanks hadar, That is what I got as well, but what I want and more importantly, What it should have done was my example below

    What I get: = Example:
    Hi_2 = Hi_1
    Hi_2 = Hi_2
    yes = yes
    Hi_6 = Hi_1
    Hi_6 = Hi_2
    Hi_6 = Hi_3
    Hi_6 = Hi_4
    Hi_6 = Hi_5
    Hi_6 = Hi_6
    Hi_3 = Hi_1
    Hi_3 = Hi_2
    Hi_3 = Hi_3
    yes = yes
    Hi_5 = Hi_1
    Hi_5 = Hi_2
    Hi_5 = Hi_3
    Hi_5 = Hi_4
    Hi_5 = Hi_5
    Hi_12 = Hi_1
    Hi_12 = Hi_2
    Hi_12 = Hi_3
    Hi_12 = Hi_4
    Hi_12 = Hi_5
    Hi_12 = Hi_6
    Hi_12 = Hi_7
    Hi_12 = Hi_8
    Hi_12 = Hi_9
    Hi_12 = Hi_10
    Hi_12 = Hi_11
    Hi_12 = Hi_12
    Hi_2 = Hi_1
    Hi_2 = Hi_2
_________________
megamog75 Smile
I will do this.Nothing in my life matters except this.No moment in my life exists except this moment.I am born in this moment, and if I fail, I will die in this moment. Raistlin Majere
Reply with quote
hogarius
Adept


Joined: 29 Jan 2003
Posts: 221
Location: islands.genesismuds.org

PostPosted: Mon Mar 31, 2014 11:28 am   
 
You want to use #LOOP instead of #REPEAT in the Else section of your #IF statement.

Code:

#Var String 2|1|6|3|1|5|12|2
#Forall @String {#If (%i = 1) {yes} {#LOOP %i {#sh hi_%j}}}


[ untested ]

Also note that I changed %i to %j toward the end of the command.
Reply with quote
megamog75
Enchanter


Joined: 20 Nov 2002
Posts: 627
Location: USA

PostPosted: Mon Mar 31, 2014 6:30 pm   
 
Thank you so much hogarius!!! Your code worked perfectly.
Where did you learn about the %j? I would love to read the documentation on that.

hogarius wrote:
You want to use #LOOP instead of #REPEAT in the Else section of your #IF statement.

Code:

#Var String 2|1|6|3|1|5|12|2
#Forall @String {#If (%i = 1) {yes} {#LOOP %i {#sh hi_%j}}}


[ untested ]

Also note that I changed %i to %j toward the end of the command.
[/b]
_________________
megamog75 Smile
I will do this.Nothing in my life matters except this.No moment in my life exists except this moment.I am born in this moment, and if I fail, I will die in this moment. Raistlin Majere
Reply with quote
hogarius
Adept


Joined: 29 Jan 2003
Posts: 221
Location: islands.genesismuds.org

PostPosted: Mon Mar 31, 2014 7:46 pm   
 
I'm not sure where I remember reading about %i , %j , ... , %r in the CMUD help files. I just remembered that is what is needed if there are multiple iteration-type statements and variables in the same trigger.

I just tried to do a quick search on %j in the knowledge base and didn't get any results. Maybe someone else more familiar with CMUD and the help files can help?
Reply with quote
megamog75
Enchanter


Joined: 20 Nov 2002
Posts: 627
Location: USA

PostPosted: Mon Mar 31, 2014 10:49 pm   
 
The above was just an Example of what I wanted to do and not the actual script.

It was your (Hogarius) idea of using the %j that made it not only work but be useful as well.
I was able to adapt this to my script and am in the middle of implementing it.

When I am finished I will post it in the finished scripts section, and give you credit for helping me, Thank you!

The script I am writing takes everything in ones inventory and places it into a new window with click-able usable links, its very involved.
_________________
megamog75 Smile
I will do this.Nothing in my life matters except this.No moment in my life exists except this moment.I am born in this moment, and if I fail, I will die in this moment. Raistlin Majere
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Tue Apr 01, 2014 12:25 am   
 
Don't quote me on where to find it, but I think you may find it discussed in #FORALL or looping-related stuff. Each nested level of a loop structure gets its own %letter variable, starting with %i. If for some horrid reason you have lots of nested levels, you would skip over any letter that already had a function.
_________________
EDIT: I didn't like my old signature
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
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

© 2009 Zugg Software. Hosted by Wolfpaw.net