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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
kmachstang
Newbie


Joined: 01 Feb 2007
Posts: 5

PostPosted: Thu Feb 01, 2007 9:05 pm   

Status Window Looping
 
Hello,

I currently have an array which contains several strings. I cannot figure out how to loop through each element of the array and output them on the status window. I tried the #FORALL command but it didn't seem to work. Anyone able to offer a suggestion?

Thanks
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Thu Feb 01, 2007 9:56 pm   
 
#forall @array {#say %i}

When you want to access each element in something like a #FORALL, you use %i. Nested loops of any kind use the next available letter down to like %z minus already-used combinations (for example, you cannot use %t or %x because they are reserved for the %1...%99 system variables (%x10, %t2, etc)).

Code:

#forall @a {
   #noop this loop uses %i
   #loop 1,6 {
      #noop this loop uses %j
   }
}


Sending them to the status window like you would send text to the chat window is completely unnecessary, unless that is what you are using instead of the traditional (and limited to one) status window.

Status Window (the below is contained in the status window itself)
%replace(@array,"|",%cr)

Child Window (the below is kept in an alias or some other setting in the main window's settings file)
#forall @array {#window Child {%i}}
_________________
EDIT: I didn't like my old signature
Reply with quote
gamma_ray
Magician


Joined: 17 Apr 2005
Posts: 496

PostPosted: Fri Feb 02, 2007 1:21 am   
 
Instead of %replace (which works) you can also use the built in function designed for this, %expandlist(@array, %cr) .

Edit: I should add, the advantage of %expandlist, besides setting you up for %expanddb when you need it, is that it only expands the main/outside list--if you have nested lists or a string containing the pipe character, it'll show that nicely... an example:

#show %expandlist("(A|B|C)|2|3",%crlf)

vs.

#show %replace("(A|B|C)|2|3","|",%crlf)
Reply with quote
kmachstang
Newbie


Joined: 01 Feb 2007
Posts: 5

PostPosted: Fri Feb 02, 2007 3:38 pm   
 
i attempted to use the

Code:
#forall @array {#window Child {%i}}


all I see in the child window is the word Array. I also tried

Code:
#FORALL @array { #SHOW %i}


and all that gets output to the terminal is the word Array again. I have no idea what is going on, I've never used a zmud loop before so this is all new to me.

Thanks for the help
Reply with quote
kmachstang
Newbie


Joined: 01 Feb 2007
Posts: 5

PostPosted: Fri Feb 02, 2007 3:49 pm   
 
Maybe im setting up my array incorrectly. I capture some text that looks like this :
Code:
RDMP 4687 PARTY_HEALTH 1 PlayerName 1778 1778 4084 4084 780 780


Pattern :
Code:
RDMP 4687 PARTY_HEALTH (%d) (%w) (%d) (%d) (%d) (%d) (%d) (%d)



Value:
Code:
statusarray.%1=%ansi( bold, blue)%1 %if( @%2==enreg OR @%2==pftc, %ansi( bold, green), %ansi( bold, red))%2 %ansi( bold, blue)%3/%4 %5/%6 %7/%8


If i then do something like #SHOW @statusarray.1 I get exactly what i want. So In my status window I have a list of variables:
Code:
@statusarray.1 %cr @statusarray.2 %cr etc...


Of course this is very messy and puts a cap on how many elements i can have in my window so I was hoping to make it dynamic with a loop. But if i do a #forall @statusarray {#SHOW %i} the word array is output.

Thank you for all your help,
Kyle
Reply with quote
gamma_ray
Magician


Joined: 17 Apr 2005
Posts: 496

PostPosted: Fri Feb 02, 2007 4:46 pm   
 
Did you try expandlist?

#show %expandlist(@statusarray,%crlf)

I am just guessing that there is something wonky with your list, for one thing you should be using %concat() to string it all together.

However, there's also A Better Way to do what you're doing. You can use a variable (db var nested inside a list, probably) to store just the information, and then use an alias to display it nicely formatted, instead of storing the formating with the data. I'll have an example in a bit.....
Reply with quote
kmachstang
Newbie


Joined: 01 Feb 2007
Posts: 5

PostPosted: Fri Feb 02, 2007 4:53 pm   
 
#show %expandlist(@statusarray,%crlf)

Also outputs the word Array. Its wierd tho, if i copy the contents of the list into another variable, called testarray both methods of output work fine...
Reply with quote
gamma_ray
Magician


Joined: 17 Apr 2005
Posts: 496

PostPosted: Fri Feb 02, 2007 6:47 pm   
 
Er. Do you have a variable called status? If so, that's the problem.... and you can probably use @{statusarray} to work around it.

Edit: Or an input trigger which #gags when you send status!

However, here's the Better Method I was talking about:

Code:
#ALIAS showparty {
  #for @party {
    #show {%ansi( bold, blue)}
    #showp {%item( %i, 1)~ }
    #if (@{%item( %i, 2)}==enreg OR @{%item( %i, 2)}==pftc) {#showp {%ansi( bold, green)}} {#showp {%ansi( bold, red)}}
    #showp {%item( %i, 2)~ }
    #showp {%ansi( bold, blue)}
    #showp {%item( %i, 3)/%item( %i, 4) %item( %i, 5)/%item( %i, 6) %item( %i, 7)/%item( %i, 8)}
    }
  }
#VAR party {(1|PlayerName|1778|1778|4084|4084|780|780)|(2|PlayerName|1778|1778|4084|4084|780|780)|(3|PlayerName|1778|1778|4084|4084|780|780)}
#TRIGGER {RDMP 4687 PARTY_HEALTH (%d) (%w %d %d %d %d %d %d)} {
  #for @party {#if (%item( %i, 1) = %1) {#delitem party %i}}
  party = %additem( %concat( %1, "|", %replace( %2, " ", "|")), @party)
  party = %sort( @party)
  }


Also, what I think you're doing from your example is using a variable for each player in a certain group, like if Bob is a member of "enreg" then you have a variable Bob with the value enreg. Instead, you should keep a variable enreg which has a list of all the players you want marked with that group, and then use %ismember, like:

Code:
#if (%ismember( %item( %i, 2), @enreg) OR %ismember( %item( %i, 2), @pftc)) {#showp {%ansi( bold, green)}} {#showp {%ansi( bold, red)}}


that way you have just two variables instead of lots and lots.
Reply with quote
kmachstang
Newbie


Joined: 01 Feb 2007
Posts: 5

PostPosted: Fri Feb 02, 2007 7:11 pm   
 
wow that works pretty good

I put a #gag at the bottom of the RDMP trigger and it keeps flashing the rdmp output and then gagging it which is rather anoying i have never seen this before??

also how do i output the showparty on the status window now? if i output the party variable with expandlist it works great but with no formatting

if i remove the for loop in the trigger the gag works fine... but i can't find anything wrong with the loop...
Reply with quote
gamma_ray
Magician


Joined: 17 Apr 2005
Posts: 496

PostPosted: Fri Feb 02, 2007 9:22 pm   
 
Oops, status window, right... Mmm. Yeah. I totally forgot about that, you're possibly going to have to go back to some variation on your original way because I can't think of any simpler way (meh).

About the gag, it is possibly just a little lag in the for loop, try putting the gag above everything else (should have no impact on that script).

I'll keep thinking about it but my latest brilliant idea crashed ZMud (annoying) and I need to run off and do some other stuff for a while, too.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD 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