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
teak
Newbie


Joined: 23 Nov 2005
Posts: 1

PostPosted: Wed Nov 23, 2005 5:12 pm   

longish #IF statement acting very strangely
 
Started building a basic grid-wandering bit of code, and I ran up against a problem in the code below. It is a large series of #IFs, and these #IFs are successively nested in the ''commands to be done if #IF statement not evaluated as true" part of their predecing events.
As it is now, the code works perfectly when the first #IF condition
Code:

#IF ( (@flag=0) AND @valid_dir(@primDir))
evaluates as true. The problem comes as soon as this first #IF statement is false. Then, the remainder of the alias is sent as half-evaluated text to the MUD. Immediately below is the output that I'm getting. Below that is the responsible code.

OUTPUT:
Code:

 630 #VAR nextStep 0
 631 {#IF (0 = 1) {#IF ( 0) {#VAR nextStep n;#SHOW {Flag 1 continuing straight}} {#IF ( 1) {#SHOW {Flag 1, hit wall, turn around. Now flag=0};#VAR nextStep {s};#VAR flag 0} {#SHOW {Flag=1, hit wall, no valid return path. MAYBE CONTINUE};#VAR nextStep 0}}} {#echo **** loaddir*********;load_dir_list;
 632     #IF ( 0) {#VAR nextStep 0} {#IF ( 0) {#VAR nextStep } {#IF ( 0) {#VAR nextStep } {#IF (0 = 2) {#SHOW {flag=2, can't reverse out. Aborting.};#BU ExplorerToggle} {#IF ( 1) {#VAR flag 2;#SHOW {Flag 2 activated, turning around.};#VAR primDir s;#VAR nextStep n} {#SHOW {Even 180 deg won't get us out of this one.};#BU ExplorerToggle}}}}};#IF (n) {#IF (0 = 2) {#VAR primDir s};
 633       #VAR flag 1} {#SHOW {BUMMER, COULDN'T FIND A PATH}}}}
 634 go north
 635 #VAR nextStep 0

The numbering 630-635 is the MUD's history buffer, from which I found out exactly what was being sent as input.


Code:

#VAR nextStep 0
#SHOW {CALC_NEXT_STEP CALLED}
#IF ( (@flag=0) AND @valid_dir(@primDir)) {
  #VAR nextStep @primDir
  #ECHO {No flag, continuing straight}
  } {
  #IF (@flag = 1) {
    #IF ( @valid_dir(@primDir)) {
      #VAR nextStep @primDir
      #SHOW {Flag 1 continuing straight}
      } {
      #IF ( @valid_dir(@reverse_dir(@primDir))) {
        #SHOW {Flag 1, hit wall, turn around. Now flag=0}
        #VAR nextStep {@reverse_dir(@primDir)}
        #VAR flag 0
        } {
        #SHOW {Flag=1, hit wall, no valid return path. MAYBE CONTINUE}
        #VAR nextStep 0
        }
      }
    } {
    #echo **** loaddir*********
    load_dir_list
   
    #IF ( @valid_dir(%item( @dirList, 1))) {#VAR nextStep %item( @dirList, 1)} {
      #IF ( @valid_dir(%item( @dirList, 2))) {#VAR nextStep %item( @dirList, 2)} {
        #IF ( @valid_dir(%item( @dirList, 3))) {#VAR nextStep %item( @dirList, 3)} {
          #IF (@flag = 2) {
            #SHOW {flag=2, can't reverse out. Aborting.}
            #BU ExplorerToggle
            } {
            #IF ( @valid_dir( @reverse_dir(@primDir))) {
              #VAR flag 2
              #SHOW {Flag 2 activated, turning around.}
              #VAR primDir @reverse_dir(@primDir)
              #VAR nextStep @primDir
              } {
              #SHOW {Even 180 deg won't get us out of this one.}
              #BU ExplorerToggle
              }
            }
          }
        }
      }
    #IF (@nextStep) {
      #IF (@flag = 2) {#VAR primDir @reverse_dir(@primDir)}
     
      #VAR flag 1
      } {#SHOW {BUMMER, COULDN'T FIND A PATH}}
    }
  }


You'll notice that there is a call to @valid_dir() and @reverse_dir() in there, and also the alias load_dir_list. These follow:
Code:

(this is the load_dir_list alias)

#IF (@primDir=n AND @secDir=w) {#var dirList "nw|w|sw"}
#IF (@primDir=n AND @secDir=e) {#var dirList "ne|e|se"}
#IF (@primDir=s AND @secDir=w) {#var dirList "sw|w|nw"}
#IF (@primDir=s AND @secDir=e) {#var dirList "se|e|ne"}
#IF (@primDir=w AND @secDir=n) {#var dirList "nw|n|ne"}
#IF (@primDir=w AND @secDir=s) {#var dirList "sw|s|se"}
#IF (@primDir=e AND @secDir=n) {#var dirList "ne|n|nw"}
#IF (@primDir=e AND @secDir=s) {#var dirList "se|s|sw"}
#IF (@flag = 2) {
  #VAR temp %item( @dirList, 3)
  #VAR dirList %replaceitem( %item( @dirList, 1), 3, @dirList)
  #VAR dirList %replaceitem( @temp, 1, @dirList)
  #UNVAR @temp
  }

this is @reverse_dir(): %item( s|n|e|w , %ismember( %1, n|s|w|e))

this is @valid_dir(): %ismember( %1, %roomexit( ))


This is also, in its current state, broken in the sense that it loops and does not stop sending that garbage to the MUD until told to stop so, as soon as it reaches this strange code. So, as you can tell, zMUD seems to take the statement it is supposed to "use" - that is, the second set of braces from the #IF statement, and evaluates some things in there, but does not execute it, if that makes sense.

Can anyone point me in the right direction as to what is going on? It all comes out very strangely.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sat Nov 26, 2005 1:41 am   
 
Without even looking at the code I can tell the problem is a missing closing brace. How it slipped past the syntax checker is beyond me, but I can not read the code without spending a large amount of time either thinking about it or reformatting it to put the braces where I expect to see them. zMud also doesn't do well with blank lines, and you should check all the lines in your script for lost trailing spaces. All to often it is the things that don't really show that casue prooblems, and for some reason those trailing spaces cause odd problems.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
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