Here is a small script to parse map text for a mud I play. In order to test it I have manually entered the value of map_written_text.
When I run it in the immediate window it outputs:
Which is exactly what I want it to do. However, when I place the script in a trigger: change line one to: and run: in the debug simulated world output I get:
I can't figure out why they would be outputting different things!? Help is greatly appreciated!
map_written_text = "A loyal McSweeney samurai is one southeast, a door east of one north, an exit southeast of two southeast, the limit of your vision is two southeast from here, a door north of two west, a bored vendor and a fat sow are two west, the limit of your vision is two west from here, doors west and east of two north, a surly youth is two north and the limit of your vision is two north from here."
re_vision = rex.new("([Tt]he limit of your vision is .+? from here(?:,|and|\.|\s)*)")
re_doors = rex.new("((?:[Aa]\s)?[Dd]oors?.*?of\s(?:(?:one|two|three|four|five)?\s?(?:north|northeast|east|southeast|south|southwest|west|northwest)|and|,|here| )+)")
re_exits = rex.new("((?:[Aa]n\s)?[Ee]xits?.*?of\s(?:(?:one|two|three|four|five)?\s?(?:north|northeast|east|southeast|south|southwest|west|northwest)|(?:and|,|here| ))+)")
re_population = rex.new("(.+?(?:is|are)(?:(?:one|two|three|four|five)?\s?(?:north|northeast|east|southeast|south|southwest|west|northwest)|and|,| )+)")
function sort_map_constructors(text, re) -- creates numeric table containing matches
matches = {}
re:gmatch(text, function (m, t)
for k, v in pairs(t) do
table.insert(matches, v)
end
end)
return matches
end
function eliminate_matches(text, t) -- eliminates matched table values from string
for _, v in ipairs(t) do
text = text:gsub(v, "")
end
return text
end
vision = sort_map_constructors(map_written_text, re_vision)
doors = sort_map_constructors(map_written_text, re_doors)
exits = sort_map_constructors(map_written_text, re_exits)
map_written_text = eliminate_matches(map_written_text, vision)
map_written_text = eliminate_matches(map_written_text, doors)
map_written_text = eliminate_matches(map_written_text, exits)
population = sort_map_constructors(map_written_text, re_population)
Note("VISION:")
table.foreach (vision, print)
Note("DOORS:")
table.foreach (doors, print)
Note("EXITS:")
table.foreach (exits, print)
Note("POPULATION:")
table.foreach (population, print)
When I run it in the immediate window it outputs:
VISION:
1 the limit of your vision is two southeast from here,
2 the limit of your vision is two west from here,
3 the limit of your vision is two north from here.
DOORS:
1 a door east of one north,
2 a door north of two west,
3 doors west and east of two north,
EXITS:
1 an exit southeast of two southeast,
POPULATION:
1 A loyal McSweeney samurai is one southeast,
2 a bored vendor and a fat sow are two west,
3 a surly youth is two north and
Which is exactly what I want it to do. However, when I place the script in a trigger:
^.+from here\.$map_written_text = GetRecentLines (1)A loyal McSweeney samurai is one southeast, a door east of one north, an exit southeast of two southeast, the limit of your vision is two southeast from here, a door north of two west, a bored vendor and a fat sow are two west, the limit of your vision is two west from here, doors west and east of two north, a surly youth is two north and the limit of your vision is two north from here.
VISION:
1 the limit of your vision is two southeast from here, a door north of two west, a bored vendor and a fat sow are two west, the limit of your vision is two west from here, doors west and east of two north, a surly youth is two north and the limit of your vision is two north from here.
DOORS:
EXITS:
POPULATION:
1 A loyal McSweeney samurai is I can't figure out why they would be outputting different things!? Help is greatly appreciated!