Trigger/script to find what is missing?

Post Reply
Posts: 1
Joined: Mon Aug 13, 2018 2:11 am

Trigger/script to find what is missing?

Post by Spronti » Mon Aug 13, 2018 2:19 am

Hey everyone, my understanding of scripting/programming is rudimentary at best. I usually make do with the basic targeting and alias structure in the helpfile. That said, I have shied away from a number of prep dependent classes in my mud, because of trouble tracking all of the affects.

Is it possible in mudlet to craft something that will tell you what is missing from a list? What I imagining is setting up a list of possible affects, and then when I type "affect" to display what I currently have up, it will respond with what is missing from the original list?


Posts: 1094
Joined: Wed Apr 03, 2013 2:19 am

Re: Trigger/script to find what is missing?

Post by Jor'Mox » Mon Aug 13, 2018 6:52 pm

In short, yes, that is very possible.

To lay out simply what my process would be for something like what you are talking about, I would use an alias for "affect" such that in addition to sending "affect" to the game (it would need to use send("affect") in addition to the rest of what it does), it would turn on some triggers. Those triggers would capture each of the affects you see from the command being sent, as well as a trigger that detects when the list is finished. The affect triggers would simply store whatever affect was captured in a table, thereby creating the list you would be comparing to the list you have made in advance that you want to check against. When the trigger that says all the affects are done fires, you would compare the two tables to see what was missing from the captured list, and then do whatever you wanted based on that. The easiest way to make such a comparison is to use the table.n_complement function, which will take two tables with nearly identical entries and return all the items present in the first one that aren't present in the second one, which I think is exactly what you want to do.

So, to sum up, and lay out some code examples, the alias would be something like this:
Code: [show] | [select all] lua
enableTrigger("affect trigger")
enableTrigger("affect end trigger")
The trigger that captured each of the affects would have a capture group in it that let you identify the affect reliably, and its code would look something like this:
Code: [show] | [select all] lua
affects_table = affects_table or {}
And the trigger that let you know you were done with the affects would have code that looks something like this:
Code: [show] | [select all] lua
disableTrigger("affect trigger")
disableTrigger("affect end trigger")
local affects_list = {'affect 1','affect 2', etc...}
local missing = table.n_complement(affects_list,affects_table)
for _,v in ipairs(missing) do
    -- do something here, this loop will step through the missing affects, which each one being stored in the variable "v"

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests