Generic Mapping Script

All and any discussion and development of the Mudlet Mapper.
Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

Re: Generic Mapping Script

Post by Jor'Mox »

Yup, you definitely want to handle closed doors and such, for the same reason you want to handle the "can't move that direction" case. The script logs directions, and only removes one when a room is seen, so if you enter a direction but don't see a new room, problems are caused.

Interesting that following doesn't include a direction. Usually I have seen something like "You follow so and so east." or whatever. And just so you know, the difference between a "onRandomMove" and "onForcedMove" is that a random move has no direction to use, so it searches adjacent rooms for a match, whereas a forced move has a direction, so it goes that way. Normal following (in which you know the direction you are moving) would count as a forced move.

Intort
Posts: 15
Joined: Wed Aug 29, 2018 1:49 pm

Re: Generic Mapping Script

Post by Intort »

i have set it as RandomMove cuz it was sudden NPC's lead and don't remember if there was a 'entering to N' type of line.
for the moment, im away from Avatar Mud.

instead, i have been trying to delete "," (comma) and "and" from matches[2] of Exits trigger.
target mud is The Two Towers MUD this time.

t2t mud has 2 mode for expression. verbose and brief.
default exits are "N W S E U D", enter, out and cardinal ways.
in verbose mode, room expression is like this. (no color separation in real screen)

This is the main street of Bywater. To your north you see the rathermain
street of Bywater
run-down looking town hall. The main road also makes a turn to the east
and continues. To the west stands the Hobbiton courthouse.
The sun shines down from directly overhead.
A light wind blows from the southwest, and clouds form overhead.
The only obvious exits are west, south, east and north.
HP:50 EP:50>


in brief mode, (again, no color separation in real screen)

Bywater's main street(w, s, e and n)
A playful hobbit child
HP:50 EP:50>

as combined exits trigger, (usually im playing in brief mode. but when "look"ed, room text becomes to verbose temporarily.)
patterns(2):
\((.*)\) --for brief mode
^\s*The only obvious exits? (?:are|is) (.*)\. --for verbose mode
script(default=as is):
Code: [show] | [select all] lua
local exits = string.gsub(matches[2],"and","")
map.prompt.exits = exits
raiseEvent("onNewRoom")
default trigger gave me a hint, but string.gsub replaces only 1 strings. and this script is to delete "and" only.
so im getting a result of 'west, south, east north' (verbose) or 'w, s, e n' (brief)
there are commas attached to west,south and w,s.
so, those are not recognized as exits.


additionally, there are so called "named direction" like "bar" or "counter" in the room. which has no exit and is just interactive like shop NPC but counted and shown in exits line/part.
so, i have no idea how should i do.
simplest way might be to limit to only conventional exits. but there should be a case when this could be a door with direction.
also, swim and boat seems to be separated way.


i have tried many things to make Exits trigger working like using string.find(failed/not fully understand) or just making a table to call from within string.gsub (currently working on).

my failing script
Exit:
Code: [show] | [select all] lua
Del = {}
table.insert(Del, "[color=#FF0000],[/color]")
table.insert(Del, "[color=#FF0000]and[/color]")
local exits = string.gsub(matches[2],DT,"")
map.prompt.exits = exits
raiseEvent("onNewRoom")
print(map.prompt.exits)
should i make a function instead ?


Room Name, Prompt and on Failed Move triggers seems to be working properly.
but there was a room of no-name in verbose mode.... im getting headache.

Room Name trigger
patterns(4 and verbose type are increasing):
^(.+)\( --for brief
^\s+This is the (.+)\. --for verbose
^\s+You now stand in the (.+)\. --for verbose
^\s+You are on the (.+)\. --for versose
script:
map.prompt.room = matches[2]


Prompt Trigger
pattern:
^HP\:\d+
script:
raiseEvent("onPrompt")


Failed Move Trigger
patterns(2):
You can't go that way! --exact matching
^The .+ is closed.
script:
raiseEvent("onMoveFail")


EDIT:
i found a way. simple stack of string.gsub did the job. :D
script became like this.

Exits Trigger(seems ok ?)
patterns(2):
\((.*)\) --for brief
^\s*The only obvious exits? (?:are|is) (.*)\. --for verbose
script:
Code: [show] | [select all] lua
s = string.gsub(matches[2],",","")
local exits = string.gsub(s,"and","")
map.prompt.exits = exits
raiseEvent("onNewRoom")
print(map.prompt.exits)
i could execute "start mapping <new area name>" command and mapper starts working at last.

but there are no exits drawn on room and strange thing is happening.
the echoes of exits are shown like this. (underline represents blank space. since its automatically cut here.)
north_east__south <<< between east and south, originally where "and" was put, has 2 blank spaces.
its same with brief type.
n_e__ s

seems there are still some mistakes in somewhere.

Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

Re: Generic Mapping Script

Post by Jor'Mox »

So, for starters, you don't need to remove "and" or commas from directions. Both of those are so common that I built them into the script, and it will take care of them for you.

Given that the brief room name and the verbose "room name" don't match, and that you typically are walking around in brief mode, I would recommend not even bothering to try to capture information from the verbose version, since there will be no way to make them match up. The script requires an exact match of room names (not counting letter cases), and in the example you provided, it is clear that won't be achievable.

One thing that might be an issue is the short directions for the exits in brief mode, but that can be corrected like this:
Code: [show] | [select all] lua
local dirs = {n = 'north', s = 'south', w = 'west', e = 'east', d = 'down', u = 'up'}
local exits = matches[2]
exits = exits:gsub("%a+",dirs)
map.prompt.exits = exits
raiseEvent("onNewRoom")
print(map.prompt.exits)

Intort
Posts: 15
Joined: Wed Aug 29, 2018 1:49 pm

Re: Generic Mapping Script

Post by Intort »

all my effort was ...nvm, after i could have managed to squash needless blank space. hehehe.
it was quite simple. by adding single blank space behind of "and", it got resolved.
fixed NOT FOR USE ANYMORE script:
Code: [show] | [select all] lua
s = string.gsub(matches[2],",","")
local exits = string.gsub(s,"and ","")  --changed "and" to "and "
map.prompt.exits = exits
raiseEvent("onNewRoom")
print(map.prompt.exits) 
about suggested script. thank you so much. it worked fine :)
i have utilized similar script (found somewhere in older posts) when making Exits trigger for one of mud whose exits are extremely simple.
[ewsn] -- <<< no blank space between each direction. just wesnud only. no diagonal move.

back to the case of Two Towers mud.
there were another needs for extra pattern matching.

1) aside from target text line "<room name>(exits)", there was a place where "campfire(burning)" appearing in the next line in brief mode.
and was worse than first look. its temporal.
naturally trigger picks additional 'burning' word as exit, but non-interactive.
its a scenery expression just to inform player of camping place.
so no matter how i set it as exit from mapper, its going to lose connection.

2) water route for swimming or boat. which is separated by "[" and "]" and has unique color (light cyan) for direction text. seems far less confusing.

not prepared for case 2) yet, but did for case 1).
Exit trigger
pattern(not changed):
\((.*)\)
script:
Code: [show] | [select all] lua
local pre = matches[2]
pre = pre:gsub("burning","")
-- these are the additional lines of unwanted-word disposer.

local dirs = {n = 'north', s = 'south', w = 'west', e = 'east', d = 'down', u = 'up', ne = 'northeast', nw = 'northwest', se = 'southeast', sw = 'southwest', enter = 'in'}
-- added all diagonal directions and tried to change 'enter' into 'in', but somehow it partially works. 'out' is omitted since it has same expression. 

local exits = pre
exits = exits:gsub("%a+",dirs)
map.prompt.exits = exits
raiseEvent("onNewRoom")
print(map.prompt.exits)
i feel serious need of 'auto unwanted word collector' trigger (table or db ?) now.
Last edited by Intort on Mon Sep 03, 2018 5:47 pm, edited 1 time in total.

Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

Re: Generic Mapping Script

Post by Jor'Mox »

So, assuming your room name line is always first, I think the easier solution is to set a boolean variable whenever you see the room name, reset it when you see your prompt, and any time your trigger fires while the variable is set, just pretend like nothing happened, like so:
Code: [show] | [select all] lua
if not found_exits then
  found_exits = true
  local dirs = {n = 'north', s = 'south', w = 'west', e = 'east', d = 'down', u = 'up', ne = 'northeast', nw = 'northwest', se = 'southeast', sw = 'southwest', enter = 'in'}
  -- added cardinal directions and tried to change all 'enter' to 'in', but somehow it partially works. 'out' is ignored since its same expression. 

  local exits = matches[2]
  exits = exits:gsub("%a+",dirs)
  map.prompt.exits = exits
  raiseEvent("onNewRoom")
  print(map.prompt.exits)
end
And obviously set found_exits to false in your prompt trigger.

Intort
Posts: 15
Joined: Wed Aug 29, 2018 1:49 pm

Re: Generic Mapping Script

Post by Intort »

somehow, that script didn't work.
once switched to it, mapper stops working.

Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

Re: Generic Mapping Script

Post by Jor'Mox »

Did you also add this to your prompt trigger?: found_exits = false

Without that, you would only ever find your exits a single time. The reset is key.

Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

Re: Generic Mapping Script

Post by Jor'Mox »

So, I'll admit I haven't wandered around until I found a fire, but I connected to Two Towers, and got the mapper working in brief mode using these two triggers:
Room Name and Exits pattern: ^([A-Z].*)\(([\w\s,]+)\)
Code: [show] | [select all] lua
if not found_exits then
	found_exits = true
	map.prompt.room = matches[2]
	map.prompt.exits = matches[3]
	raiseEvent("onNewRoom")
end
Prompt pattern: ^HP:.*>
Code: [show] | [select all] lua
found_exits = false
raiseEvent("onPrompt")

Intort
Posts: 15
Joined: Wed Aug 29, 2018 1:49 pm

Re: Generic Mapping Script

Post by Intort »

thanks for quick reply.

oh, overlooked the note of last line.
i had just copy&pasted. after changing the line to 'find_exits = false', it started working.
besides, i needed to add old pattern of verbose as well for Exits trigger due to connection lost after using "look" to see verbose texts.
currently, im experimenting 'onForcedMove' trigger.
when running from enemy by wimpy condition fired up, it won't follow my move. though i added a pattern of "^You\srun\s(.+)\.$" <<(plain text is like this. "You run South").

and thanks for your extra labor... i didn't even imagine combined trigger.
i have tested them for both of existing and new profile.
sadly, these set of triggers doesn't work well. even though it starts mapper and shows proper output with "print(map.prompt.xxx)" lines added.
it keeps duplicating rooms. apparently exits are not connected as expected.
Glitched Connection.png
Glitched Connection.png (29.63 KiB) Viewed 11742 times

btw, this is just out of curiosity.
a pattern for the trigger of room name, how to choose just 1st line ?
i mean, in case room name is on top of each room's description, but when color can't be used as trigger.
default trigger is for the case (matches to most mud) which is based on condition that it had single unique color.

but if the line had non-distinct color (like old non-ansi screen output), or had 2 or more colors like this ?
"This is the Training Room for Warrior"

Intort
Posts: 15
Joined: Wed Aug 29, 2018 1:49 pm

Re: Generic Mapping Script

Post by Intort »

about last question of 1st line for room name trigger.
i could make pattern matching but not tested. it looks so simple.
anyway,
presuming first letter of 1st line was capital.
simple first line = room name trigger
Pattern:
^([A-Z][\w\s]+)$\n
Script(simplest):
Code: [show] | [select all] lua
map.prompt.room  = matches[1]
print(map.prompt.room)--debug line
or default script.
Last edited by Intort on Wed Sep 05, 2018 5:41 pm, edited 2 times in total.

Post Reply