|
animal2011 Beginner
Joined: 24 Feb 2011 Posts: 11
|
Posted: Thu Feb 24, 2011 3:29 pm
Problem with selecting room exit choices |
Hi,
Wondering if anyone could clear this problem up for me...
I am trying to make a set of triggers to walk in random, existing directions. My plan was to use something like this:
pattern
There * obvious exit*: (*).
contents
#forall {%replace( "%1", ",", "|")} {#additem exits %i}
#ALARM "a1" +5 {
#1 {%item( @exits, %random( 1, %numitems))}
#var exits {}
}
Room exit text looks like this
There are 6 obvious exits: north, south, east, up, enter house and west.
Problem is, it just doesn't work, the following problems have become apparent:
-none standard exits like "enter house" it will pick up the word enter but not house when I don't want it to pick up either, i just want it to pick standard compass directions.
-it always seems to return the first result it picked up which often causes a loop of walking back and forth between 2 rooms.
I just want it to wander n,s,e,w,ne,nw,se,sw preferably without going the same way it just came unless there is only 1 exit.
I've read the helpfiles and played around and googled but to no avail, any ideas? |
|
Last edited by animal2011 on Thu Feb 24, 2011 4:39 pm; edited 1 time in total |
|
|
|
animal2011 Beginner
Joined: 24 Feb 2011 Posts: 11
|
Posted: Thu Feb 24, 2011 4:35 pm |
ok, had a slight breakthrough here...
#forall {%replace( "%1", ",", "|")} {#additem exits %i}
#ALARM "a1" +5 {
#1 %item( @exits, %random( 1, %numitems( @exits)))
#var exits {}
}
seems to be working in regards to my random walking but I still don't know how to make it only match standard exits. |
|
|
|
DraxDrax Apprentice
Joined: 22 Mar 2009 Posts: 149
|
Posted: Thu Feb 24, 2011 5:38 pm |
Try something like...
Code: |
#VAR directions {north|east|south|west|northeast|northwest|southeast|southwest|down|up}
#VAR reverse_directions {south|west|north|east|southwest|southeast|northwest|northeast|up|down}
#VAR last_direction ""
#TRIGGER {There * obvious exit*: (*).} {
#VAR exits ""
#FORALL {%replace("%1", ", ", "|")} {#IF %ismember(%i, @directions) {#ADDITEM exits %i}}
#IF (%numitems(@exits) > 1) {#DELITEM exits %item(@reverse_directions, %ismember(@last_direction, @directions))}
#ALARM "a1" +5 {
#VAR last_direction %item(@exits, %random(1, %numitems(@exits)))
#1 @last_direction
}
} |
This checks the arguments returned by the trigger against a list of 'directions' and only adds items that match that list in to 'exits'. It then checks to see if there's more than a single valid exit to choose from and, if there is, removes the reverse from the list of possible exits. So, if you just moved 'east' you won't backtrack 'west', unless that's the only way to go.
Hope that helps. |
|
|
|
animal2011 Beginner
Joined: 24 Feb 2011 Posts: 11
|
Posted: Thu Feb 24, 2011 7:34 pm |
OK, thanks for the help, however I entered that and it created the trigger and the variables however most times when I look, after the 5 second alarm it enters a blank line rather than a direction like so:
There are two obvious exits: west and southeast.
>
>
Sadly I don't know where to begin picking it apart since I didn't write it and admittedly have very little scripting experience. |
|
|
|
Myrkul Wanderer
Joined: 21 Aug 2008 Posts: 85
|
Posted: Thu Feb 24, 2011 7:47 pm |
[edit][/edit]
|
|
Last edited by Myrkul on Thu Apr 14, 2011 11:04 pm; edited 1 time in total |
|
|
|
animal2011 Beginner
Joined: 24 Feb 2011 Posts: 11
|
Posted: Thu Feb 24, 2011 7:52 pm |
I tried that earlier today and ended up adding a whole new line for replacing the and with |, is there a way to replace all ,'s and ands with | in 1 replace command? I tried the help files and searching here but I couldn't find an example to work from :\
Sorry for being a pain in the ass, I hate having to ask for help but this has me beat. |
|
|
|
Myrkul Wanderer
Joined: 21 Aug 2008 Posts: 85
|
Posted: Thu Feb 24, 2011 8:03 pm |
[edit][/edit]
|
|
Last edited by Myrkul on Thu Apr 14, 2011 11:04 pm; edited 1 time in total |
|
|
|
animal2011 Beginner
Joined: 24 Feb 2011 Posts: 11
|
Posted: Thu Feb 24, 2011 8:11 pm |
Thanks Myrkul, I was just totally failing at nesting the and section, if nothing else I now know how to properly nest replaceables :D
Sadly, it still doesn't seem to work as intended, on some screens it returns the same blank line as previously and on screen where it does work it seems to aways take the 1st listed exit which is fine until you have 2 rooms which list the joining exit first.
It currently looks like this:
#VAR exits ""
#FORALL {%replace( %replace( %1, ", ", "|"), " and ", "|")} {#IF %ismember( %i, @directions) {#ADDITEM exits %i}}
#IF (%numitems( @exits) > 1) {#DELITEM exits %item( @reverse_directions, %ismember( @last_direction, @directions))}
#ALARM "a1" +5 {
#VAR last_direction %item( @exits, %random( 1, %numitems( @exits)))
#1 @last_direction
} |
|
|
|
Myrkul Wanderer
Joined: 21 Aug 2008 Posts: 85
|
Posted: Thu Feb 24, 2011 9:00 pm |
[edit][/edit]
|
|
Last edited by Myrkul on Thu Apr 14, 2011 11:03 pm; edited 1 time in total |
|
|
|
animal2011 Beginner
Joined: 24 Feb 2011 Posts: 11
|
Posted: Thu Feb 24, 2011 9:06 pm |
ok, here is an example
There are four obvious exits: enter stall, east, north and northwest.
>
A delirious traveller arrives from the north.
> |
|
|
|
Myrkul Wanderer
Joined: 21 Aug 2008 Posts: 85
|
Posted: Thu Feb 24, 2011 9:19 pm |
[edit][/edit]
|
|
Last edited by Myrkul on Thu Apr 14, 2011 11:03 pm; edited 1 time in total |
|
|
|
DraxDrax Apprentice
Joined: 22 Mar 2009 Posts: 149
|
Posted: Thu Feb 24, 2011 9:23 pm |
Not sure how I missed the need to replace 'and' in the arguments with pipes. Sorry about that, and good catch, Myrkul.
Right now, I think the problem is that you don't have quotes around the %1 in your nested %replace() functions. Without quoting that, zMud will think that any commas it passes are delimiters for arguments. Cmud parses things a little differently and the quotes wouldn't be needed.
So try: %replace(%replace("%1", ", ", "|"), " and ", "|") |
|
|
|
animal2011 Beginner
Joined: 24 Feb 2011 Posts: 11
|
Posted: Thu Feb 24, 2011 9:27 pm |
yeah, when it returned the blank result, the exits variable was blank and when it keeps picking the first listed exit the exits variable only contains 1 entry.
|
|
|
|
Myrkul Wanderer
Joined: 21 Aug 2008 Posts: 85
|
Posted: Thu Feb 24, 2011 9:29 pm |
[edit][/edit]
|
|
Last edited by Myrkul on Thu Apr 14, 2011 11:03 pm; edited 1 time in total |
|
|
|
animal2011 Beginner
Joined: 24 Feb 2011 Posts: 11
|
Posted: Thu Feb 24, 2011 9:31 pm |
so in cmud that would work?
can zmud triggers be imported to cmud? |
|
|
|
Myrkul Wanderer
Joined: 21 Aug 2008 Posts: 85
|
Posted: Thu Feb 24, 2011 9:41 pm |
[edit][/edit]
|
|
Last edited by Myrkul on Thu Apr 14, 2011 11:02 pm; edited 1 time in total |
|
|
|
animal2011 Beginner
Joined: 24 Feb 2011 Posts: 11
|
Posted: Thu Feb 24, 2011 9:46 pm |
Guess I'll have to find some sort of zmud workaround as I plain old can't afford to buy cmud right now :(
|
|
|
|
DraxDrax Apprentice
Joined: 22 Mar 2009 Posts: 149
|
Posted: Thu Feb 24, 2011 9:58 pm |
Have you tried: %replace(%replace("%1", ", ", "|"), " and ", "|") ?
|
|
|
|
animal2011 Beginner
Joined: 24 Feb 2011 Posts: 11
|
Posted: Thu Feb 24, 2011 10:08 pm |
DraxDrax wrote: |
Not sure how I missed the need to replace 'and' in the arguments with pipes. Sorry about that, and good catch, Myrkul.
Right now, I think the problem is that you don't have quotes around the %1 in your nested %replace() functions. Without quoting that, zMud will think that any commas it passes are delimiters for arguments. Cmud parses things a little differently and the quotes wouldn't be needed.
So try: %replace(%replace("%1", ", ", "|"), " and ", "|") |
I totally missed that entire post, sorry, that fixed it, it's all shiny now, thank you.
One more tiny thing (I hope)
Any way to turn the output to the mud from "southeast" to "se"? |
|
|
|
DraxDrax Apprentice
Joined: 22 Mar 2009 Posts: 149
|
Posted: Thu Feb 24, 2011 10:24 pm |
Yep, try this:
#VAR directions {north|east|south|west|northeast|northwest|southeast|southwest|down|up}
#VAR short_directions {n|e|s|w|ne|nw|se|sw|d|u}
#VAR reverse_directions {s|w|n|e|sw|se|nw|ne|u|d}
#VAR last_direction ""
#TRIGGER {There * obvious exit*: (*).} {
#VAR exits ""
#FORALL {%replace(%replace("%1", ", ", "|"), " and ", "|")} {#IF %ismember(%i, @directions) {#ADDITEM exits %item(@short_directions, %ismember(%i, @directions))}}
#IF (%numitems(@exits) > 1) {#DELITEM exits %item(@reverse_directions, %ismember(@last_direction, @short_directions))}
#ALARM "a1" +5 {
#VAR last_direction %item(@exits, %random(1, %numitems(@exits)))
#1 @last_direction
}
}
Changes in bold. |
|
|
|
animal2011 Beginner
Joined: 24 Feb 2011 Posts: 11
|
Posted: Thu Feb 24, 2011 10:32 pm |
DraxDrax wrote: |
Yep, try this:
#VAR directions {north|east|south|west|northeast|northwest|southeast|southwest|down|up}
#VAR short_directions {n|e|s|w|ne|nw|se|sw|d|u}
#VAR reverse_directions {s|w|n|e|sw|se|nw|ne|u|d}
#VAR last_direction ""
#TRIGGER {There * obvious exit*: (*).} {
#VAR exits ""
#FORALL {%replace(%replace("%1", ", ", "|"), " and ", "|")} {#IF %ismember(%i, @directions) {#ADDITEM exits %item(@short_directions, %ismember(%i, @directions))}}
#IF (%numitems(@exits) > 1) {#DELITEM exits %item(@reverse_directions, %ismember(@last_direction, @short_directions))}
#ALARM "a1" +5 {
#VAR last_direction %item(@exits, %random(1, %numitems(@exits)))
#1 @last_direction
}
}
Changes in bold. |
Perfect! Thanks a million. |
|
|
|
DraxDrax Apprentice
Joined: 22 Mar 2009 Posts: 149
|
Posted: Thu Feb 24, 2011 10:40 pm |
:) Glad I could help.
|
|
|
|
|
|