Mudlet Questions

by Rika

Back to Mechanic's Corner.

Illidor2011-07-06 22:19:59
What exactly is the point of raising user defined events? You can assign them to functions individually, but unless I am mistaken, each function needs to be in it's own script file? Why is this better than just having my prompt trigger call each function in it's scripting box?
Vadi2011-07-06 23:48:14
For that case, it's not really. But events are good for coordinating many different plugins - one plugin can raise an event, and other, third-party ones, can use the event. Or when your system gets bigger, you'll notice that it's good to raise events for something generic - like an enemy entering the room - that'll have many different hooks do their own thing for that event, instead of one giant function.
Sylphas2011-07-06 23:51:24
It makes maintaining your code easier, too. Ideally, all your triggers would ever do is model the game state, and raise events. That can all happen safely away from any code that actually does anything. Once it's working, you just hook those events whenever you need them to do something. If you had them call functions instead, you'd have to either edit the trigger code each time or have a kludgy function that is basically just a router.
Unknown2011-07-07 03:19:02
So, I guess this is the best place for Lua questions too?
I'm in Mudlet and trying to define my own data structure, a dictionary whose keys are strings and values are arrays. Is there a nice way to do that so I can define functions for this data structure and then call them like the functions for Lua tables--ex. table.insert() or table.remove()? Basically, how do I define mydictionary so I can call myDictionary.insert() and myDictionary.remove()?
Vadi2011-07-09 02:16:55
mytable = {}

mytable:remove()
mytable:insert(...)

Note that the shortcodes won't work if the table is a local one - you'd do table.remove(mytable), table.insert(mytable, ...) then.
Ardmore2011-07-13 02:59:08
I have my own tabbed chat, and I just installed IFF. I'm trying to push the colouring into my chat, but I figure that the temp triggers are firing after everything else, so the tabbed chat is already populated before the colouring is applied.

Is my logic correct? Is there a way for me to fix this so my chat gets coloured names as well?
Lilia2011-07-13 05:20:45
QUOTE (Ardmore @ Jul 12 2011, 09:59 PM) <{POST_SNAPBACK}>
I have my own tabbed chat, and I just installed IFF. I'm trying to push the colouring into my chat, but I figure that the temp triggers are firing after everything else, so the tabbed chat is already populated before the colouring is applied.

Is my logic correct? Is there a way for me to fix this so my chat gets coloured names as well?

That sounds right. I'm pretty sure they fire in the order they're created, and the coloring triggers are created after the system loads. When I updated my chat box, the colors transferred, but only for the rest of that session.
Unknown2011-07-16 11:33:27
I'm in Mudlet 2.0-rc6-pre1 and I've been running to this problem with raised events. My spelling matches. I clicked the plus sign so the event is in the registered event handlers field. The script name matches the function name.
If someone can find where I messed up, I'd be really grateful. Thanks.

trigger on exact match: You are wielding: OR You aren't wielding anything in either hand
CODE
raiseEvent("clearSphereList") -- this line doesn't work
--empowerPrimary.clearSpheres() -- this line works when I uncomment it; the function below works


script: clearSpheres
registered event handler: clearSphereList
CODE
function empowerPrimary:clearSpheres()
    for k, colour in ipairs(empowerPrimary.sphereColours) do
        empowerPrimary.spheres = {}
    end
    empowerPrimary:echoSpheres() -- echo shows empty list
end


debug console
CODE
new line arrived:You aren't wielding anything in either hand.

Trigger name=inventory(You aren't wielding anything in either hand.) matched.
LUA: ERROR running script clearSpheres (clearSpheres) ERROR:clearSphereList
LUA OK script inventory (Trigger34) ran without errors
Unknown2011-07-16 11:50:54
Declaring and calling it with different syntax, using '.' versus ':', may have unexpected results. If you use ':', you get an implicitly declared 'self' variable that refers to the current table/module. I used to use this syntax, but now I've switched over to more of a module-based coding model.
Vadi2011-07-16 12:01:57
You also need to have:

function clearSpheres()

As your function name, because that's your script name. (or you can go with function empowerPrimary_clearSpheres() for now - it doesn't accept : or . yet for the event handler function)
Unknown2011-07-16 12:18:13
Ooh. Thanks Zarquan. Thanks Vadi.

I've been poking at the Lua-Users wiki articles on modules. I don't understand which way of coding modules is best though.

Edit: I've gone with using tables and locals where possible. I can refer to my spheres by colour now, whee.
Zalandrus2011-07-22 03:22:36
Two basic questions as I try to set up all my aliases:

-How do I reference an alias in another alias or in a macro? E.g. if "bash" is my alias for "point scalpel bashtar", how do I get another alias to do 'bash'?

-My macros don't seem to be working...in the one that m&m includes for bashing, I replaced "kick" with my bashing attack, but pressing F3 doesn't do anything? The system isn't paused. Do I need to turn macros 'on' or something?
Lilia2011-07-22 05:08:54
QUOTE (Zalandrus Meyedsun @ Jul 21 2011, 10:22 PM) <{POST_SNAPBACK}>
Two basic questions as I try to set up all my aliases:

-How do I reference an alias in another alias or in a macro? E.g. if "bash" is my alias for "point scalpel bashtar", how do I get another alias to do 'bash'?

-My macros don't seem to be working...in the one that m&m includes for bashing, I replaced "kick" with my bashing attack, but pressing F3 doesn't do anything? The system isn't paused. Do I need to turn macros 'on' or something?

expandAlias("bash"), though that's not recommended. You should make a function that does what 'bash' does, and then any alias you need call that function.

That keybinding is inactive when you first install m&m. Double click it so there's a check mark in the box.
Jarael2011-07-22 05:52:24
How exactly would I trigger something to perform the last command entered? Or is that possible? Specifically, I'm wanting to trigger something like "You fumble drunkenly" to re-send the command that caused that.
Lilia2011-07-22 06:09:08
QUOTE (Jarael @ Jul 22 2011, 12:52 AM) <{POST_SNAPBACK}>
How exactly would I trigger something to perform the last command entered? Or is that possible? Specifically, I'm wanting to trigger something like "You fumble drunkenly" to re-send the command that caused that.

send("!")
Ytran2011-07-22 08:01:56
QUOTE (Lilia @ Jul 22 2011, 01:09 AM) <{POST_SNAPBACK}>
send("!")

This only works if you sent no commands between sending the last command and sending the !. For example, if you send

CODE
outr myrtle
eat myrtle


together (which wouldn't be a terribly uncommon thing to do), and you get the fumbling message from the outr, by the time you send !, your last command is eat myrtle.

Other instances this would be a problem is if you are sending commands while your system is working, and so forth.

So, to answer Jarael's question, there isn't really a good way to do that in the general case, since you can't feasibly know 100% what command is causing the fumbling. If you can guarantee that you will only ever send one command at a time, and will always wait for a server response before sending another, something along the lines of send("!") can work, or an alias/trigger combo set up like:

CODE
Alias pattern: ^.*$
Alias script: last_string_sent = matches

Trigger pattern:
Trigger script: send(last_string_sent)


However, this is not an ideal situation.
Vadi2011-07-22 11:02:30
QUOTE (Jarael @ Jul 22 2011, 01:52 AM) <{POST_SNAPBACK}>
How exactly would I trigger something to perform the last command entered? Or is that possible? Specifically, I'm wanting to trigger something like "You fumble drunkenly" to re-send the command that caused that.


You wouldn't want to do it that way, because if you send two commands in a succession, and both fail, you'd double do the last one or somesuch.
Jalain2011-07-22 23:41:55
How do I set an alias so it will only work on the exact command? I have PS set to point staff target, but it goes off whenever I try to search shops and anything else with PS in it. Is it ^ps?
Neos2011-07-22 23:43:47
QUOTE (Jalain @ Jul 22 2011, 07:41 PM) <{POST_SNAPBACK}>
How do I set an alias so it will only work on the exact command? I have PS set to point staff target, but it goes off whenever I try to search shops and anything else with PS in it. Is it ^ps?

^ps$
Jarael2011-07-23 02:07:15
QUOTE (Vadi @ Jul 22 2011, 06:02 AM) <{POST_SNAPBACK}>
You wouldn't want to do it that way, because if you send two commands in a succession, and both fail, you'd double do the last one or somesuch.


Hmm, that's true. Also, thanks Ytran. That does make sense even if it's not ideal like you said.

I might just set the message to echo " failed!" or somesuch and see how that works and manual the misses, unless I can think of a better solution.