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
Nexes
Beginner


Joined: 23 Mar 2003
Posts: 28

PostPosted: Thu Jun 10, 2004 1:24 am   

Help with a loop
 
I have an alias that looks like this:

#ALIAS captell {#PRI {captellstring=%2
numwords_capstring=%numwords( @captellstring)
currentword=1
current_char_number=2
current_finished_word_pos=1}
#WHILE (@numwords_capstring>=@currentword) {
length_word=%len( %word( @captellstring, @currentword))
word_inprogress=%word( @captellstring, @currentword)
curr_fin_number=1
#WHILE (@current_char_number<=@length_word) {
#IF (%left( @word_inprogress, 1)=a) {
word_inprogress=%remove( a, @word_inprogress)
word_inprogress=%insert( A, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=b) {
word_inprogress=%remove( b, @word_inprogress)
word_inprogress=%insert( B, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=c) {
word_inprogress=%remove( c, @word_inprogress)
word_inprogress=%insert( C, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=d) {
word_inprogress=%remove( d, @word_inprogress)
word_inprogress=%insert( D, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=e) {
word_inprogress=%remove( e, @word_inprogress)
word_inprogress=%insert( E, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=f) {
word_inprogress=%remove( f, @word_inprogress)
word_inprogress=%insert( F, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=g) {
word_inprogress=%remove( g, @word_inprogress)
word_inprogress=%insert( G, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=h) {
word_inprogress=%remove( h, @word_inprogress)
word_inprogress=%insert( H, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=i) {
word_inprogress=%remove( i, @word_inprogress)
word_inprogress=%insert( I, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=j) {
word_inprogress=%remove( j, @word_inprogress)
word_inprogress=%insert( J, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=k) {
word_inprogress=%remove( k, @word_inprogress)
word_inprogress=%insert( K, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=l) {
word_inprogress=%remove( l, @word_inprogress)
word_inprogress=%insert( L, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=m) {
word_inprogress=%remove( m, @word_inprogress)
word_inprogress=%insert( M, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=n) {
word_inprogress=%remove( n, @word_inprogress)
word_inprogress=%insert( N, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=o) {
word_inprogress=%remove( o, @word_inprogress)
word_inprogress=%insert( O, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=p) {
word_inprogress=%remove( p, @word_inprogress)
word_inprogress=%insert( P, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=q) {
word_inprogress=%remove( q, @word_inprogress)
word_inprogress=%insert( Q, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=r) {
word_inprogress=%remove( r, @word_inprogress)
word_inprogress=%insert( R, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=s) {
word_inprogress=%remove( s, @word_inprogress)
word_inprogress=%insert( S, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=t) {
word_inprogress=%remove( t, @word_inprogress)
word_inprogress=%insert( T, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=u) {
word_inprogress=%remove( u, @word_inprogress)
word_inprogress=%insert( U, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=v) {
word_inprogress=%remove( v, @word_inprogress)
word_inprogress=%insert( V, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=w) {
word_inprogress=%remove( w, @word_inprogress)
word_inprogress=%insert( W, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=x) {
word_inprogress=%remove( x, @word_inprogress)
word_inprogress=%insert( X, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=y) {
word_inprogress=%remove( y, @word_inprogress)
word_inprogress=%insert( Y, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=z) {
word_inprogress=%remove( z, @word_inprogress)
word_inprogress=%insert( Z, @word_inprogress, 1)
}
finishedword=%insert(%left(@word_inprogress,2), @finishedword, @curr_fin_number)
curr_fin_number=((@curr_fin_number)+2)
word_inprogress=%remove(%left(@word_inprogress, 2), @word_inprogress)
current_char_number=((@current_char_number)+2)
}
finished_string=%insert( @finishedword, @finished_string, @current_finished_word_pos)
current_finished_word_pos=((@current_finished_word_pos)+(%len( @finishedword)+1))
current_char_number=2
currentword=((@currentword)+1)
}
tell %1 @finished_string}

Now, to clarify I want it to do this:
INPUT:captell someone hello
OUTPUT:tell someone HeLlO

Yes, I know its a bit of a pointless alias but I wanted to see how it would be done. Now, I try to use this alias but it just goes into an infinite loop and I can't figure out why it would do that. Can anyone tell me why?
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Thu Jun 10, 2004 2:09 am   
 
The problem is with these 2 lines:
current_char_number=((@current_char_number)+2)
currentword=((@currentword)+1)

zMud uses a string/text basis for all variables and generally processes things as strings with implicit concantenation. That means that when @currentword="1" this line "currentword=((@currentword)+1)" results in @currentword="((1)+1)". You have to use either #MATH or %eval to tell zMud to process it mathematically. For example:
#MATH currentword {((@currentword)+1)}
currentword=%eval((@currentword)+1)

You also have a few logic problems. You are %insertING into both finishedword and finished_string without %removeING from them or blanking them. In the case of finishedword I would suggest blanking it at the start of the loop and then %concatING on the 2 characters. Since your already counting in current_char_number use that in your #IFs instead of always %removeING the letters.

You can also use %concat to develop the finished_string variable, just make sure you tack on spaces when needed. This eliminates the current_finished_word_pos variable. You would still have to blank finished_string at the start of the alias.

You can eliminate the #PRIORITY command entirely. It does nothing in the current configuration and is not really needed for any of the loops.
Reply with quote
Nexes
Beginner


Joined: 23 Mar 2003
Posts: 28

PostPosted: Thu Jun 10, 2004 2:26 am   
 
Ahh, okies, I made the changes the way you suggested and this is what I got:

#ALIAS captell {captellstring=%2
numwords_capstring=%numwords( @captellstring)
currentword=1
current_char_number=2
current_finished_word_pos=1
#VAR finished_string {}
#WHILE (@numwords_capstring>=@currentword) {
length_word=%len( %word( @captellstring, @currentword))
word_inprogress=%word( @captellstring, @currentword)
curr_fin_number=1
#WHILE (@current_char_number<=@length_word) {
#IF (%left( @word_inprogress, 1)=a) {
word_inprogress=%remove( a, @word_inprogress)
word_inprogress=%insert( A, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=b) {
word_inprogress=%remove( b, @word_inprogress)
word_inprogress=%insert( B, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=c) {
word_inprogress=%remove( c, @word_inprogress)
word_inprogress=%insert( C, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=d) {
word_inprogress=%remove( d, @word_inprogress)
word_inprogress=%insert( D, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=e) {
word_inprogress=%remove( e, @word_inprogress)
word_inprogress=%insert( E, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=f) {
word_inprogress=%remove( f, @word_inprogress)
word_inprogress=%insert( F, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=g) {
word_inprogress=%remove( g, @word_inprogress)
word_inprogress=%insert( G, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=h) {
word_inprogress=%remove( h, @word_inprogress)
word_inprogress=%insert( H, @word_inprogress, 1)
}

...

#IF (%left( @word_inprogress, 1)=w) {
word_inprogress=%remove( w, @word_inprogress)
word_inprogress=%insert( W, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=x) {
word_inprogress=%remove( x, @word_inprogress)
word_inprogress=%insert( X, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=y) {
word_inprogress=%remove( y, @word_inprogress)
word_inprogress=%insert( Y, @word_inprogress, 1)
}
#IF (%left( @word_inprogress, 1)=z) {
word_inprogress=%remove( z, @word_inprogress)
word_inprogress=%insert( Z, @word_inprogress, 1)
}
finishedword=%concat(@finishedword, %left(@word_inprogress,2))
curr_fin_number=((@curr_fin_number)+2)
word_inprogress=%remove(%left(@word_inprogress, 2), @word_inprogress)
current_char_number=%eval((@current_char_number)+2)
}
finished_string=%insert( @finishedword, @finished_string, @current_finished_word_pos)
current_finished_word_pos=((@current_finished_word_pos)+(%len( @finishedword)+1))
current_char_number=2
currentword=%eval((@currentword)+1)
}
tell %1 @finished_string}

I did the eval and stuff and the concat for the finishedword. I didn't do the concat for the finished string because that would have taken a bit more revisions and since I already have something that (I think) should work I don't really want to change it. Also, I didn't understand the part that I don't have to remove from the word. I attempted to do it without removing it (by getting the 2 charachter then the 4 charachter and so on) but when I tried to do it I realized left would give the first two charachters if I did that. I couldn't find a way just to get the character at the end so...I didn't do it. Anyways, does it look right?
Reply with quote
Nexes
Beginner


Joined: 23 Mar 2003
Posts: 28

PostPosted: Thu Jun 10, 2004 2:36 am   
 
Allrighty, I tested the alias, didn't work. The good thing is it didn't go into an infinite loop! *cheer* For some reason it only seems to modify the first word...and even then it does it badly. Then the words after the first word do not get modified at all. It also fails to modify the first word properly in a very ugly fashion.

INPUT:captell hi hi
OUTPUT:tell hi HiHiHiHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHh...HhHhHhHhHhHhHhHhHhHhHhHh
HhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhH
hHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHh
HhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHhHiHi

The "..." represents a HUGE chunk of repeating Hh's. While it didn't go on forever it was still a bit long. Can anyone tell me why it did that?
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Thu Jun 10, 2004 11:31 am   
 
Replace this section:
#WHILE (@current_char_number<=@length_word) {
#IF (%left( @word_inprogress, 1)=a) {
word_inprogress=%remove( a, @word_inprogress)
word_inprogress=%insert( A, @word_inprogress, 1)
}
....
finishedword=%concat(@finishedword, %left(@word_inprogress,2))
curr_fin_number=((@curr_fin_number)+2)
word_inprogress=%remove(%left(@word_inprogress, 2), @word_inprogress)
current_char_number=%eval((@current_char_number)+2)
}

with:
#VAR finishedword {}
#WHILE (%len(@word_inprogress)) {
#IF (%lower(%left( @word_inprogress, 1))=%left( @word_inprogress, 1)) {
finishedword=%concat(@finishedword,%proper(%copy(@word_inprogress,1,2)))
} {
finishedword=%concat(@finishedword,%copy(@word_inprogress,1,2))
}
word_inprogress=%copy(@word_inprogress, 3,255)
}
}

Also you need to use %eval on this line
current_finished_word_pos=((@current_finished_word_pos)+(%len( @finishedword)+1))
Reply with quote
Nexes
Beginner


Joined: 23 Mar 2003
Posts: 28

PostPosted: Fri Jun 11, 2004 12:26 am   
 
I tried adding your suggested changes and it gave me syntax errors. I'll have to try and figure out why it did that before I do anything else. But to make sure I understood I am to get rid of all the IF's that check the letters and replace it yes?
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Fri Jun 11, 2004 11:16 am   
 
Thats right a single #IF will handle the whole thing. I have one too many closing brace at the end. There are quite a few other changes that could be made to further simplify the alias. Even in what I wrote for you things could be changed to be shorter.
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