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
Loftaris
Adept


Joined: 24 Aug 2004
Posts: 277

PostPosted: Wed Feb 10, 2016 2:31 pm   

Map path to alias
 
Is there a way to store a random path into an alias?

What I want to do, is store a path from my current room number, to another room number, in an alias.

I'm in room A, and want to run to room B, I can just #walk %roomvnum, but my problem is that it prevents my killswitch from working properly, so if I can store it in an alias, and then just fire the alias, that would solve my problem, however I don't know how to do this.

Please and thank you very much, you guys are awesome!
Reply with quote
Loftaris
Adept


Joined: 24 Aug 2004
Posts: 277

PostPosted: Wed Feb 10, 2016 2:47 pm   
 
I figured out how to get the path stored into a variable (#var pathStored = {%walk(%1)} .. But I don't know how to use the variable to send the commands to the mud to make me move.
Reply with quote
Loftaris
Adept


Joined: 24 Aug 2004
Posts: 277

PostPosted: Wed Feb 10, 2016 4:18 pm   
 
I apparently figured out my own problem, I was using the wrong () to set the alias, it's now working. Thanks for looking :)

#var pathStored {%walk(%1)}
#al pathWalk @pathStored
Reply with quote
shalimar
GURU


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

PostPosted: Wed Feb 10, 2016 4:50 pm   
 
#PATH is the intended way to save a speedwalk, but you can store it in a variable if you prefer.
_________________
Discord: Shalimarwildcat
Reply with quote
Loftaris
Adept


Joined: 24 Aug 2004
Posts: 277

PostPosted: Wed Feb 10, 2016 5:11 pm   
 
Hrm. I think I misunderstood the use of a path, I've only used them as a stepper. However, I don't know if that would work, because when CMud sends paths to the game, CMud interprets that as user-inputted commands, whereas aliases do not.

This only matters because I use a deadman switch in my game, and user-inputted commands interrupt the idle time, causing me to never go idle. Using an alias instead of a path prevents this from happening, so if I idle too long, my character stops moving, and prevents me from suffering wizard punishments. Bots are legal, unattended bots are not, hence the deadman switch as a backup precaution.
Reply with quote
Loftaris
Adept


Joined: 24 Aug 2004
Posts: 277

PostPosted: Wed Feb 10, 2016 6:11 pm   
 
Alright, so my experiment failed. Anytime I have to use a path, whether it's in an alias (I assume because it's using .directions, that it's using the path feature) .. So instead of it sending the commands, it's pathing the commands.

So, I'm at a loss again of how to do this.
Reply with quote
shalimar
GURU


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

PostPosted: Wed Feb 10, 2016 6:24 pm   
 
var=%pathexpand(%walk(%1))
then you can %pop(var) to get the next direction, and delete it at the same time
_________________
Discord: Shalimarwildcat
Reply with quote
Loftaris
Adept


Joined: 24 Aug 2004
Posts: 277

PostPosted: Wed Feb 10, 2016 7:21 pm   
 
Thank you very much Shalimar. I will test this when I get home later. I have a few ideas on how I think I can get this to work! It's still using h,j etc directions, which require a . which is a path.. but if I convert those to nw/se, etc, that would bypass the pathing problem...

Appreciate the help!
Reply with quote
shalimar
GURU


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

PostPosted: Thu Feb 11, 2016 1:32 am   
 
%pathexpand should take care of that for you... but if not:
#HELP %replace
_________________
Discord: Shalimarwildcat
Reply with quote
Loftaris
Adept


Joined: 24 Aug 2004
Posts: 277

PostPosted: Thu Feb 11, 2016 1:34 am   
 
Well so far I haven't got to test it yet, I just finished implementing it. I created a wild script to change it all over.

In theory, it's working.. But, I'll know in about 10 minutes if it works properly :)

It looks like this.

Code:
pathStored = (%walk(%1))

pathWalk = %pathexpand(@pathStored)

#until (!@pathWalk) {pathNext = %pop(@pathWalk)
  #if (@pathNext = "h") {pathNext = "nw"}
  #if (@pathNext = "j") {pathNext = "ne"}
  #if (@pathNext = "k") {pathNext = "sw"}
  #if (@pathNext = "l") {pathNext = "se"}
  #if (@pathNext = ".(enter bus)") {pathNext = "enter bus"}
  #if (@pathNext = ".(leave)") {pathNext = "leave"}
  #send @pathNext
  }
Reply with quote
shalimar
GURU


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

PostPosted: Thu Feb 11, 2016 1:40 am   
 
looks good, i would probably use a #SWITCH instead of all those #IFs, but whatever works.
_________________
Discord: Shalimarwildcat
Reply with quote
Loftaris
Adept


Joined: 24 Aug 2004
Posts: 277

PostPosted: Thu Feb 11, 2016 1:41 am   
 
I've never been able to grasp the use of #switch. A few friends have tried to show me, but it just doesn't make sense in my brain for some reason. I've read the help files, had a friend send me a script and I've tried adapting it to my use, but ... It just doesn't click. I've wanted to use #switch SO MANY TIMES because I think it would have more practical use.... But... Nada...

I'd be excited to see an example though if you're willing :)
Reply with quote
shalimar
GURU


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

PostPosted: Thu Feb 11, 2016 1:44 am   
 
Using the example you have there:

Code:
#SWITCH (@pathNext)
  ("h") {pathNext = "nw"}
  ("j") {pathNext = "ne"}
  ("k") {pathNext = "sw"}
  ("l") {pathNext = "se"}
  (".(enter bus)") {pathNext = "enter bus"}
  (".(leave)") {pathNext = "leave"}
_________________
Discord: Shalimarwildcat
Reply with quote
Loftaris
Adept


Joined: 24 Aug 2004
Posts: 277

PostPosted: Thu Feb 11, 2016 1:47 am   
 
Thank you shalimar. I see what you did.. I am pretty sure I've tried that in the past but with no success... Maybe I've made some typos, I don't know.... Thanks so much for the input.

One question, are you missing {} brackets around the h/j/k/l/etc switches? How does it know when to stop switching?

Maybe that's why I couldn't get it to work.. It looks funny to me...

For the record, I've never taken a programming course, all the code I know I've taught myself, learned from other scripts, or had others assist me. So I truly truly appreciate all your help, this is fantastic!
Reply with quote
shalimar
GURU


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

PostPosted: Thu Feb 11, 2016 2:35 am   
 
It knows via context (the parser), technically you can have that all on one line, but i spaced it out for legibility.
Excess white space outside of quote marks is irrelevant.
_________________
Discord: Shalimarwildcat
Reply with quote
shalimar
GURU


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

PostPosted: Thu Feb 11, 2016 5:21 am   
 
#SWITCH (@testVariable) ("possible value one") {do something} ("passible value 2") {do something else} {default action if no match}
_________________
Discord: Shalimarwildcat
Reply with quote
Llohr
Apprentice


Joined: 17 May 2005
Posts: 108

PostPosted: Thu Feb 11, 2016 11:21 am   
 
Keep in mind, #SWITCH is particular about your indent style. You have to make sure that you indent the "(expression)". If you try to start a line with it, the parser won't understand it.

As for how it knows when to stop: a switch will stop the first time a condition is met. That makes it a fair bit more efficient than using a series of #IFs, though it would probably (or so I imagine) be comparable to a NESTED series of #IFs (where the next if is only checked if the previous one failed). Adding in a local variable so I don't have to type out quite so much, that would look something like:
Code:
$a=@pathNext
#if ($a="h") {
    $a="nw"
} {
   #if ($a="j") {
        $a="ne"
    } {
        #if ($a="k") {
            $a="nw"
        } {
            #if ($a="l") {
                $a="se"
            } {
                #if ($a=".(enter bus)") {
                    $a="enter bus"
                } {
                    #if ($a=".(leave)") {
                        $a="leave"
                    }
                }
            }
        }
    }
}
#send $a


And now we're just getting crazy! That's obviously not something you want to do here, but it might look better in another situation.

To remake your script with some locals to avoid the creation of unnecessary variables (since it looks like you're sending all the directions at once and then you're done with the path), you could do:
Code:

$Path=%pathexpand(%walk(%1))
#WHILE ($Path) {
    $Next=%pop($Path)
    #Switch ($Next)
        ("h") {$Next="nw"}
        ("j") {$Next="ne"}
        ("k") {$Next="sw"}
        ("l") {$Next="se"}
        (".(enter bus)") {$Next="enter bus"}
        (".(leave)") {$Next="leave"}
    #send $Next
}

Locals variables are handy, and you don't have to worry about giving them unique names--they only exist within the block of code (or alias/trigger/function/macro) where they're created.


Shalimar, that "#help <subject>" thing is the greatest thing I've seen all day.
Reply with quote
Loftaris
Adept


Joined: 24 Aug 2004
Posts: 277

PostPosted: Thu Feb 11, 2016 12:29 pm   
 
Thank you very much guys. That's a wealth of knowledge and I appreciate your help!
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Thu Feb 11, 2016 2:57 pm   
 
I am doing this off the top of my head since my CMud machine is down.
Code:
pathWalk = %subregex(%pathexpand(@pathStored),"(?<=\A|\|)(?:\.\(([^\)]+)\)|(h|j|k|l))(?=\Z|\|)","(?(1)\1|%item(""nw\|ne\|sw\|se\|"",(?MEMBER:2)))")
That should replace the h,j,k,l and strip out the .() on other directions.

Sending all the directions at once like that might not be what you want for a complex script. I use a series of triggers that detects moving through rooms and sends the next item in the path after it has confirmed movement and has no issues. Anyhow if I did that right it will all be in a variable and then you can do what you want.
_________________
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 » 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