script, alias? trigger??? named exits

Post Reply
aespe
Posts: 6
Joined: Thu Feb 11, 2016 2:08 pm

script, alias? trigger??? named exits

Post by aespe » Fri Sep 23, 2016 2:55 pm

ok, exits pop up on the screen as I enter each new room like this

"Exits: north, east, south, west."

and i have made aliases on to open exit n and os for open exit s, when there are normal doors. Sometimes however, there are named doors, and they look like this

"Exits: north, east, south, -w:bushes"

I was wanting "something" that remembers the wildcard and lets me open, lock, close etc wildcard. or something that lets my alias "ow" open exit west and then also if w:bushes it "opens wildcard", but only when I type the alias. I have been able to make it fire automatically with a send, but I do not want it to fire automatically, I only want it to fire when I type. I dont want it to just open, but to close, lock, unlock, bash, etc. Inside of the trigger window I have been able to have mudlet send and setup aliases in the mud when the wildcard triggers. This solution would work except that it pumps spam into the screen. for each named exit, it may be locked. so I can set the mud to make aliases for open wildcard, unlock wildcard, bash wildcard, lock wildcard, close wildcard but it becomes 6 lines of spam for every door and it can get too much when you are going back and forth between rooms.
I messed around with raiseevent after watching the video from vadi, and maybe the closest I came was trying to have my alias "ow" enableTrigger() only when I am in a room with w:(w/+.)\. I never could get it to work though, and I saw alot on if then end stuff, but I could never figure out what I am supposed to write.

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

Re: script, alias? trigger??? named exits

Post by Jor'Mox » Fri Sep 23, 2016 3:41 pm

So, I would do it like this. First, use your exit triggers to capture the relevant info, call a function in a script made for that purpose, and use the function to store the appropriate name to use for a given exit, defaulting to the directions. Then all of your other aliases also call functions, which then pull from the stored variables set when you captured the exits.

aespe
Posts: 6
Joined: Thu Feb 11, 2016 2:08 pm

Re: script, alias? trigger??? named exits

Post by aespe » Sat Sep 24, 2016 9:05 am

Ok, I think I have an idea of what to do but I need some more direction. I guess that's my question, where/how/with what command do I store the (\w\+), And then the trigger activates the function by just having the words function() on the clipboard below?

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

Re: script, alias? trigger??? named exits

Post by Jor'Mox » Sat Sep 24, 2016 11:56 am

Okay, so I wasn't sure if you would need help with writing the code or not, so I whipped up a simple script that should be able to do what you need, and a regex pattern to match (assuming that the normal directions were divided from the ones with wildcard names by a single hyphen, as opposed to one before each wildcard exit). This is the pattern I used: ^Exits: (?:([\w, ]+))?(?:-([\w, :]+))?$
And the code for the trigger should be this: parseMyExits(matches[2],matches[3])

And then you have this as a script on its own.
Code: [show] | [select all] lua
local directions = {n = "north", s = "south", e = "east", w = "west", nw = "northwest",
    ne = "northeast", sw = "southwest", se = "southeast", u = "up", d = "down"}
    
local exits = {}

function parseMyExits(dir1,dir2)
    dir1 = string.trim(dir1)
    dir2 = string.trim(dir2)
    local exits = {}
    for w in string.gmatch(dir1,"\w+") do
        table.insert(exits,w)
    end
    for d,w in string.gmatch(dir2,"(\w+):(\w+)") do
        table.insert(exits,d)
        table.insert(exits,w)
    end
    setMyExits(unpack(exits))
end

function setMyExits(...)
    exits = {}
    local dir
    for i,v in ipairs(args) do
        if table.contains(directions,v) then
            if dir then
                exits[dir] = dir
            end
            dir = directions[v] or v
        elseif dir then
            exits[dir] = v
            dir = nil
        else
            error("setExits: arguments must be just directions or directions followed by names")
        end
    end
end

function getMyExit(dir)
    dir = directions[dir] or dir
    return exits[dir] or dir
end
Then, for your aliases in which you want to use the appropriate word to interact with an exit, you would do something like this:
send("open " .. getMyExit("n"))

You could also make a more generic, single alias to handle opening exits in any direction (rather than one per exit), like this:
pattern: ^o (\w+)$
code: send("open " .. getMyExit(matches[2]))

If I guessed wrong about how the exits are displayed, then obviously the regex would need to be adjusted. And depending on how wrong I was, the code might need to be adjusted as well to properly divide up directions for use. But just post an appropriate example demonstrating a case where it messes up, and I should be able to tweak things for you.

chrio
Posts: 66
Joined: Mon Aug 22, 2016 11:34 am

Re: script, alias? trigger??? named exits

Post by chrio » Sat Sep 24, 2016 12:18 pm

aespe wrote:Ok, I think I have an idea of what to do but I need some more direction. I guess that's my question, where/how/with what command do I store the (\w\+), And then the trigger activates the function by just having the words function() on the clipboard below?
Some basics:
Code: [show] | [select all] lua
-- IN TRIGGER To store the content of (\w\+) in a global variable named someVar:
someVar = matches[2]


-- IN A SCRIPT making a function named doStuff that uses someVar somewhere 
function doStuff(whatToDo)
  send( whatToDo .. " " .. someVar )
end


-- IN THE ALIAS, to call the function and if what you want to do with someVar is "bash [someVar's content]"
doStuff("bash")

User avatar
SlySven
Posts: 903
Joined: Mon Mar 04, 2013 3:40 pm
Location: Deepest Wiltshire, UK
Discord: SlySven#2703

Re: script, alias? trigger??? named exits

Post by SlySven » Sun Sep 25, 2016 1:29 am

I am currently coding some features that might make this easier to do in the short to medium term and to allow it to be automated into automatically found routes - I am intending to allow the command that is sent to the Mud server to be customised on an exit by exit basis (and for the defaults to be redefined which non-English Mud players will really like I think!) There will be commands to set/reset and get the "exit command" and this will also be accessible from the 2D mapper GUI - though the current prototype only has limited screen real-estate to show it.

BTW It is already possible to script up code to store "door" names in the Room User Data structure. Don't forget that some MUDs have doors with different names for this vs. the other side which can impact on the scripting. From a representation point of view the current 2D mapper does not handle two way exits with different door "types" (colours) but that is one thing that will be "fixed" in the future.

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

Re: script, alias? trigger??? named exits

Post by Jor'Mox » Sun Sep 25, 2016 12:44 pm

I think in this case, at least, the mapper is not a good solution, as someone who is just learning Mudlet at this level is unlikely to be able to set up a mapping script of any sort, no matter how simplified.

aespe
Posts: 6
Joined: Thu Feb 11, 2016 2:08 pm

Re: script, alias? trigger??? named exits

Post by aespe » Sun Sep 25, 2016 2:34 pm

Thanks for all the help everyone. You are correct about me having no ability to set up mapper. I do find it easier for me to set up triggers aliases etc in this program than any other however. I just got it in my head to try to make these named exits work and I got in too deep and I was just spending no time mudding and all time trying to get the actions working. Thanks for all the info!!!

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests