mIRC Home    About    Download    Register    News    Help

Print Thread
#176228 06/05/07 04:38 PM
Joined: Feb 2007
Posts: 75
T
Babel fish
OP Offline
Babel fish
T
Joined: Feb 2007
Posts: 75
Been trying to write a fast walk for my Mud client script, but messed up quite badly. I want to use the default method of one string to display multipul direction inputs like: 2n4w6e(twice north, 4 times west and 6 times east) or 2n2d2n(twice north, twice down and twice north), but my script doesn't seem to do that at all, but works for single inputs. How can I mod it so it can take multipul directions(like say 2n5e2n6e) and make it work in sequence it is typed?

Code:
;===========
; Fast Walk
;===========
alias fw {
  ;Retreaving Information
  ;----------------------

  %direct =  $1

  ;North
  ;-----
  %north = $wildtok(%direct, *n, 1, 32)
  if (%findn != $null) { %north = $gettok(%direct,%findn) }
  if (($len(%north) > 1) && (%north != $null)) { %nnum = $abs(%north) }
  if (($len(%north) = 1) && (%north != $null)) { %nnum = 1 }
  echo 4 %north

  ;East
  ;----
  %east = $wildtok(%direct, *e, 1, 32)
  if (($len(%east) > 1) && (%east != $null)) { %enum = $abs(%east) }
  if (($len(%east) = 1) && (%east != $null)) { %enum = 1 }

  ;South
  ;-----
  %south = $wildtok(%direct, *s, 1, 32)
  if (($len(%south) > 1) && (%south != $null)) { %snum = $abs(%south) }
  if (($len(%south) = 1) && (%south != $null)) { %snum = 1 }

  ;West
  ;----
  %west = $wildtok(%direct, *w, 1, 32)
  if (($len(%west) > 1) && (%west != $null)) { %wnum = $abs(%west) }
  if (($len(%west) = 1) && (%west != $null)) { %wnum = 1 }

  ;Processing Information
  ;----------------------

  if (%north != $null) {
    %fwi = %nnum
    %fdo = $remove(%north,%nnum)

    while %fwi > 0 {
      echo 4 %fdo
      dec %fwi
    }
  }
  if (%east != $null) {
    %fwi = %enum
    %fdo = $remove(%east,%enum)

    while %fwi > 0 {
      echo 4 %fdo
      dec %fwi
    }
  }
  if (%south != $null) {
    %fwi = %snum
    %fdo = $remove(%south,%snum)

    while %fwi > 0 {
      echo 4 %fdo
      dec %fwi
    }
  }
  if (%west != $null) {
    %fwi = %wnum 
    %fdo = $remove(%west,%wnum)

    while %fwi > 0 {
      echo 4 %fdo
      dec %fwi
    }
  }

  unset %north %east %south %west
  unset %nnum %enum %snum %wnum
}

(using echo instead of sockwrite until I can get it to work...)


GigIRC Network Admin
irc.gigirc.com
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Well, you'd need to do something along these lines:

Code:
alias fastwalk {
  var %cnt = 1,%total = $len($1)
  while (%cnt <= %total) {
    if ($mid($1,%cnt,1) isnum) {
      var %number = $iif(%number,%number $+ $mid($1,%cnt,1),$mid($1,%cnt,1))
    }
    else var %direction = $mid($1,%cnt,1)
    inc %cnt
    if (%direction) {
      echo -a $str(%direction,$iif(%number,$v1,1))
      unset %number %direction
    }
  }
}


Now, that will turn:
2n4w6e

into:
nn
wwww
eeeeee

If you need them all separated, you can use:
Code:
alias fastwalk {
  var %cnt = 1,%total = $len($1)
  while (%cnt <= %total) {
    if ($mid($1,%cnt,1) isnum) {
      var %number = $iif(%number,%number $+ $mid($1,%cnt,1),$mid($1,%cnt,1))
    }
    else var %direction = $mid($1,%cnt,1)
    inc %cnt
    if (%direction) {
      if (!%number) var %number = 1
      while (%number) {
        echo -a %direction
        dec %number
      }
      unset %number %direction
    }
  }
}


That will echo each movement on separate lines. Just change the ECHO to whatever command you use to move around.


Invision Support
#Invision on irc.irchighway.net
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
Do the actions have to occur in the order they are given, or can all the N be done at once? Or should the difference between N and S be calculated (ie 5n + 8s = 3s) and then sent once? If I gave the command /fw 3n5w7s4e9n8w list the commands that should be sent to the server.

-genius_at_work

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Knowing how MUDs work, you'd want it to follow the path in the order that it's given so that it knows if you are allowed to move in the direction chosen.


Invision Support
#Invision on irc.irchighway.net
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
This should do what is necessary:

Code:
alias fw {
  ;syntax: /fw 1n2w3s4e
  var %r = $1
  while ($regsub(fw,%r,/(\d+)([news])/i,,%r)) {
    echo -a $str($regml(fw,2),$regml(fw,1))
  }
}



/fw 1n2e3s4w5n6e7w8s
=
n
ee
www
ssss
nnnnn
eeeeee
wwwwwww
ssssssss


-genius_at_work

Joined: Feb 2007
Posts: 75
T
Babel fish
OP Offline
Babel fish
T
Joined: Feb 2007
Posts: 75
Just needed to output on a seprate line each, but with a mod of your regular expression script, I got it to do just that.

Thanks to both of you for the help smile


GigIRC Network Admin
irc.gigirc.com
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
I really do need to learn to use regular expressions... frown


Invision Support
#Invision on irc.irchighway.net
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
Regular Expressions are one of the most useful things I've ever found in any programming language. A good part of regex is that you can learn the basics first, and then expand to the more complex parts later.

-genius_at_work

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Unfortunately, when I looked into it before, I didn't understand the information in the tutorials that I found and because it's not something that I *need*, I just haven't tried to figure it out. I think that what I need is someone to explain it to me sometime... or just more incentive to figure it out. smile


Invision Support
#Invision on irc.irchighway.net

Link Copied to Clipboard