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


Joined: 06 Apr 2003
Posts: 15

PostPosted: Sun Apr 20, 2003 7:06 pm   

Problem with #if =~ in #while
 
the poblematic piece of code is that:

bef_string=%replace( @bef_string, ", den Kampf", " koennen. Den Kampf")
#WHILE (%pos( "Den Kampf mit", @bef_string)) {#IF (@bef_string =~ "*Den Kampf mit (%w) musst Du (*) koennen.*") {
#SAY %%1 : %%2
bef_temp=" Den Kampf mit "%%1" musst Du "%%2" koennen."
bef_string=%remove( @bef_temp, @bef_string)
bef_temp=""
}}

the %%1 and %%2 references are emty in the loop. Is it normal cause it's in a while loop? Or is there an error in my code.
Are ther any alternatives.
The thing is, in my string there can be zero, one or more occurences of the pattern, and a normal if only gets the first one, so i must du a loop.
Is it eventually possible to put the pattern in the #while statement, and then refer to the %%1 and %%2 like:
#WHILE (@bef_string =~"*Den Kampf mit (%w) musst Du (*) koennen.*") {
#SAY %%1 : %%2
....
}
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Mon Apr 21, 2003 2:47 pm   
 
If you are using this at the command line, I think you just use %1 and %2.

There are probably easier ways to do this but it's hard to tell without context, especially in a language I don't speak.

The (*) in
(@bef_string =~ "*Den Kampf mit (%w) musst Du (*) koennen.*")
will match all the bold text below. I'm fairly sure that's not what you want.

Den Kampf mit WORD1 musst Du WORD2 WORD3 koennen. ANOTHER SENTENCE WITH OTHER WORDS. Den Kampf mit WORD4 musst Du WORD5 koennen.

LightBulb
Advanced Member
Reply with quote
blondi
Beginner


Joined: 06 Apr 2003
Posts: 15

PostPosted: Mon Apr 21, 2003 4:03 pm   
 
Here is the script, its not finished

#IF (@bef_string =~ "* Du hast (%d) Punkte~, brauchst aber (%d)~!*") {
#SAY Punkte: %%1 von %%2
bef_temp= " Du hast "%%1" Punkte, brauchst aber "%%2"!"
bef_string=%remove( @bef_temp, @bef_string)
bef_temp=""
}
bef_string=%replace( @bef_string, ", den Kampf", " koennen. Den Kampf") (1)
#WHILE (%pos( "Den Kampf mit", @bef_string)) {#IF (@bef_string =~ "*Den Kampf mit (%w) musst Du (*) koennen.*") {
#SAY %%1 : %%2
bef_temp=" Den Kampf mit "%%1" musst Du "%%2" koennen."
bef_string=%remove( @bef_temp, @bef_string) (2)
bef_temp=""
}}
#IF (@bef_string =~ "* Du solltest dich noch gruendlicher ausbilden lassen~!") {
#SAY Ausbildung fehlt}

bef_string contains a long string i capture over multiple lines form the mud
an example:

"Aha, so sieht es also mit Dir aus! Du kannst aus folgendem Grund nicht befoerdert werden: Deine Stufe reicht dafuer nicht aus. Du hast 50 Punkte, brauchst aber 100! Du musst mind. Stufe 12 sein. Kampftritt musst Du bald schon uebel, den Kampf mit Kyll musst Du sehr sehr uebel, den Kampf mit Bielkyll musst Du fast schlecht koennen. Du solltest Dich noch gruendlicher ausbilden lassen! Frage am Besten einen Spieler hoeheren Ranges."

(1) i think is clear, make out of the subsentences single sentences, so i need only one #if

(1) the %remove is for the #while-loop, so that the %pos-function ends the #while when no other occurences of my if pattern are in the string.
As said there can be 0, 1 or more occurences of the pattern in the string.

If this code works i would get
"Punkte 50 von 100
Kyll : sehr sehr uebel
Bielkyll: fast schlecht
Ausbildung fehlt!"

but the %%1 and %%2 pattern-references are empty.
i think it's so cause this #if =~ is in the #while-loop, it seams to be a bug:
in another script i had a #if =~ and process the %%1-reference in the commands-area of that first #if with other #if's. there was also the problem that the for the second #if the %%1 was empty, i had to assign the %%1 to a var, but here in thise code, the %%1 are always empty (i use zMud 6.40)

Generally i want to capture all the strings tranform them to a better readable form, transform the "sehr sehr uebel"-things to a numeric value (but this is no problem)

the thing you said with the (*):
i hadnt thinked about that, but i think the #if will only match the first pattern, and then if this pattern is processes the substring will be removed from the bef_string, an the #if can match the next one.
Alternatively instead of the (*) i can use the alle possibilities the will be there (but that are 15 so the script will be slow down. I know that from other scripts contain many #if's and "heavy patterns"

So thats all, thank for your help, and please excuse my anglish
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Mon Apr 21, 2003 5:14 pm   
 
I modified the original pattern to allow alphanumeric words and put it into an alias, using only the #SAY portion of the command.
#AL test1 {#IF (@bef_string =~ "Den Kampf mit (%a) musst Du (*) koennen.") {#SAY %%1 : %%2}}
Then I tested it using my sample text.
Den Kampf mit WORD1 musst Du WORD2 WORD3 koennen. ANOTHER SENTENCE WITH OTHER WORDS. Den Kampf mit WORD4 musst Du WORD5 koennen.

The output was what I expected:
WORD1 : WORD2 WORD3 koennen. ANOTHER SENTENCE WITH OTHER WORDS. Den Kampf mit WORD4 musst Du WORD5

I changed the %a back to %w, and tried your sample text after modifying it to separate subsentences:
"Aha, so sieht es also mit Dir aus! Du kannst aus folgendem Grund nicht befoerdert werden: Deine Stufe reicht dafuer nicht aus. Du hast 50 Punkte, brauchst aber 100! Du musst mind. Stufe 12 sein. Kampftritt musst Du bald schon uebel, den Kampf mit Kyll musst Du sehr sehr uebel koennen. Den Kampf mit Bielkyll musst Du fast schlecht koennen. Du solltest Dich noch gruendlicher ausbilden lassen! Frage am Besten einen Spieler hoeheren Ranges."

Here too, the results are as I expected:
Kyll : sehr sehr uebel koennen. Den Kampf mit Bielkyll musst Du fast schlecht

I also tried to test your script, but ended up with an endless #WHILE loop which just displayed line after line of:
:

It looks like you'll need to find another approach.

LightBulb
Advanced Member
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Mon Apr 21, 2003 5:38 pm   
 
Continuing to test things, I tried adding another % in case #WHILE was stripping one.
#AL test3 {#IF (@bef_string =~ "* Du hast (%d) Punkte~, brauchst aber (%d)~!*") {
#SAY Punkte: %%1 von %%2
bef_temp= " Du hast "%%1" Punkte, brauchst aber "%%2"!"
bef_string=%remove( @bef_temp, @bef_string)
bef_temp=""
}
bef_string=%replace( @bef_string, ", den Kampf", " koennen. Den Kampf")
#WHILE (%pos( "Den Kampf mit", @bef_string)) {#IF (@bef_string =~ "*Den Kampf mit (%w) musst Du (*) koennen.*") {
#SAY %%%1 : %%%2
bef_temp=" Den Kampf mit "%%%1" musst Du "%%%2" koennen."
bef_string=%remove( @bef_temp, @bef_string)
bef_temp=""
}}
#IF (@bef_string =~ "* Du solltest dich noch gruendlicher ausbilden lassen~!") {#SAY Ausbildung fehlt}}


This comes very close to the results you are looking for I think.
Punkte: 50 von 100
Bielkyll : fast schlecht
Kyll : sehr sehr uebel
Ausbildung fehlt


@bef_string is now "Aha, so sieht es also mit Dir aus! Du kannst aus folgendem Grund nicht befoerdert werden: Deine Stufe reicht dafuer nicht aus. Du musst mind. Stufe 12 sein. Kampftritt musst Du bald schon uebel koennen. Du solltest Dich noch gruendlicher ausbilden lassen! Frage am Besten einen Spieler hoeheren Ranges."

LightBulb
Advanced Member
Reply with quote
blondi
Beginner


Joined: 06 Apr 2003
Posts: 15

PostPosted: Mon Apr 21, 2003 6:50 pm   
 
Thank you very much, that's it
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