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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
ryan0_o
Beginner


Joined: 17 Aug 2016
Posts: 19

PostPosted: Wed Aug 17, 2016 9:03 am   

Simple Travel Script Porting
 
Code:

#class {travel} {kill}
#class {travel} {open}

#var travel 0

#function {revdir}
{
     #switch {"%1"}
     {
          #case {"north"} {#return south};
          #case {"east"}  {#return west};
          #case {"south"} {#return north};
          #case {"west"}  {#return east};
          #case {"up"}    {#return down};
          #case {"down"}  {#return up}
     }
}
 
#function {longdir}
{
     #switch {"%1"}
     {
          #case {"n"} {#return north};
          #case {"e"} {#return east};
          #case {"s"} {#return south};
          #case {"w"} {#return west};
          #case {"u"} {#return up};
          #case {"d"} {#return down}
     }
}
 
#function {shortdir}
{
     #switch {"%1"}
     {
          #case {"north"} {#return n};
          #case {"east"}  {#return e};
          #case {"south"} {#return s};
          #case {"west"}  {#return w};
          #case {"up"}    {#return u};
          #case {"down"}  {#return d}
     }
}
 
#function {finddir}
{
     #if {"%1" != "%2"}
     {
          #return %2
     }
     {
          #return %3
     }
}

#alias {travel}
{
     #if {$travel}
     {
          #var travel 0;
          #showme <118>You stop traveling.
     }
     {
          #var travel 1;
          #var lastdir @longdir{%0};
          #var lastdir @revdir{$lastdir};
          %0
     }
}

#act {[Exits: %1]}
{
     #if {$travel}
     {
          #if {"%1" != "%* %*"}
          {
               #var travel 0;
          }

          #regex {%1} {%* %* %*}
          {
               #var travel 0;
          }

          #regex {%1} {%* %*}
          {
               #var newdir @finddir{$lastdir;&1;&2};
               #showme <118>You travel $newdir.;

               #var lastdir @revdir{$newdir};

               @shortdir{$newdir}
          }
     }     
}
{1}


Fairly simple. Was just looking to port it to CMUD. I don't want to seem as if I'm looking for a handout. I've done done research and can accomplish this, but I'm sure this is a more effective way. I'm still trying to familiarize myself with CMUDs *MANY* functions. (I.E. %revdir is already available I see)

Thanks in advance.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4691
Location: Pensacola, FL, USA

PostPosted: Thu Aug 18, 2016 10:15 am   
 
The %reversedir function works like this:

%reversedir(north) = s
%reversedir(north, 1) = south
%reversedir(%reversedir(north)) = n

Something like this would check single word commands, test them for being a direction, and if so, sets the direction you came from:

#ONINPUT {^(%w)$} {#IF (%reversedir(%1)) {lastDir=%reversedir(%1, 1)}}

Not entirely sure what else you are trying to do without an explanation.

#TR {~[Exits: (*)~]} {does something}
_________________
Discord: Shalimarwildcat
Reply with quote
ryan0_o
Beginner


Joined: 17 Aug 2016
Posts: 19

PostPosted: Thu Aug 18, 2016 11:03 am   
 
Ah sorry. It's basically a traveling script for two-way roads (rooms with only two exits)

You use alias travel (direction) and it continues until it reaches an intersection.

It basically works as is with minor changes. I just didn't know if there was a more... elegant... way to accomplish this.

Also probably worth mentioning that $ is the variable symbol and @ denotes a function for anyone trying to understand this.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4691
Location: Pensacola, FL, USA

PostPosted: Thu Aug 18, 2016 11:59 am   
 
that's what I thought
This should turn the mud output into a string list, remove your @lastdir from the list, and then check to make sure there is only one item in the list left before trying to send that as a command

#TR {~[Exits: (*)~]} {
$exits=%replace(%replace(%replace(%1, ", and ", "|"), " and ", "|"), ", ", "|")
#DELITEM $exits @lastDir
#IF (%numitems($exits)=1) {$exits}
}

in CMUD $var referances local variables, @var reverences regular variables, %func() for the predefined functions, and @func() for custom functions
There is no need for custom functions for this in CMUD though.
_________________
Discord: Shalimarwildcat
Reply with quote
ryan0_o
Beginner


Joined: 17 Aug 2016
Posts: 19

PostPosted: Thu Aug 18, 2016 9:48 pm   
 
Code:

#TR {~[Exits: (*)~]}
{
   #if {$traveling}
   {
      $exits = %replace(%replace(%replace(%1,"[",""),"]","")," ","|");
      
      #DELITEM $exits @lastDir;
      
      #if (%numitems($exits)=1)
      {
         $exits;
         #show %ansi(red)You travel $exits;
                        #var lastDir %reversedir($exits);
      }
      {
         #var traveling 0;
         #show %ansi(red)You stop traveling to pick up new directions.;
      }   
   }
}

That's what I have so far. I'll test it when I get a chance.
Reply with quote
ryan0_o
Beginner


Joined: 17 Aug 2016
Posts: 19

PostPosted: Fri Aug 19, 2016 12:22 pm   
 
Code:

#TR {~[Exits: (*)~]}
{
  #if (@traveling)
  {
    $exits = %replace(%replace(%replace(%1,"[",""),"]","")," ","|")
    #DELITEM $exits @lastDir
   
    #if (%numitems($exits)=1)
    {
      $exits
      #var lastDir %reversedir($exits,1)
      #show %ansi(red)You travel $exits
    }
    {
      #var traveling 0
      #show %ansi(red)You stop traveling to pick up new directions.
    }   
  }
}

#alias {te} {#var traveling 1;east;#var lastDir west}
#alias {tw} {#var traveling 1;west;#var lastDir east}
#alias {tn} {#var traveling 1;north;#var lastDir south}
#alias {ts} {#var traveling 1;south;#var lastDir north}
#alias {tu} {#var traveling 1;up;#var lastDir down}
#alias {td} {#var traveling 1;down;#var lastDir up}

Firing but not compiling?
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Fri Aug 19, 2016 3:48 pm   
 
I don't see any clear code problems so I am going to guess it is a formatting problem. CMud's parser is much more picky than a compiler for a programming language like C++, but even more advanced parsers require certain to tokens to be grouped in certain ways. I believe CMud requires the open brace to be on the same line as the code it relates to.

These formattings have always worked well:
Code:
#IF (condition) {
 code
} {
 code
}

#IF (condition) {code} {code}
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
ryan0_o
Beginner


Joined: 17 Aug 2016
Posts: 19

PostPosted: Fri Aug 19, 2016 9:37 pm   
 
Yes, that fixes it.

Everything works as anticipated.

Thank you sir!
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD 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