Using Lua Functions in Priority Queue

by Jules

Back to Mechanic's Corner.

Jules2009-11-07 22:03:08
I'm currently in the process of creating my own combat curing system for Mudlet, and I've been following Thorgal's thread titled "Curing System Tutorial" as kind of a guide on building this system. Now, every scripting example he gives is using the native scripting language for zMUD, which is fine, because as a programmer (well... learning to become one, anyway), I understand what he's getting at.

Within his post, he makes a mention to create variables setting every affliction to zero, and when the proper triggers fire, setting the affliction variable to one. Also, when that trigger fires, it will also fire off an alias, which will check EVERY affliction in sequence, curing them as they go. This is fine, and it looks efficient and everything, but is that the most efficient way to do it using Lua?

Lua supports the ability for user-made Functions that have a set command sequence. So, I could make a function called addAff(), and have it add the current affliction to a list, which would be handled by affCure(), which would cure all the afflictions on that list in sequence...

Now, which one is better?

I can see that the second way, using Functions, would be a little less work because I wouldn't be forced to declare all of the variables, but Thorgal's way seems viable too. Any thoughts on the subject?
Daved2009-11-07 22:46:51
Use functions. Functions are your friends. Using aliases will slow your system to a crawl.
Unknown2009-11-07 23:33:18
You should look at the source code for Treant, all written in Lua using modules, functions, and other neat things.
Jules2009-11-08 01:10:32
QUOTE (Zarquan @ Nov 7 2009, 06:33 PM) <{POST_SNAPBACK}>
You should look at the source code for Treant, all written in Lua using modules, functions, and other neat things.


Actually, that's what I've been using for a lot of reference points and stuff. I've been using that ginormeous list of affliction Triggers... Thank you!
Unknown2009-11-08 02:57:08
QUOTE (Jules @ Nov 7 2009, 08:10 PM) <{POST_SNAPBACK}>
Actually, that's what I've been using for a lot of reference points and stuff. I've been using that ginormeous list of affliction Triggers... Thank you!


The list of trigger messages is only half of it. You really need to study the Lua code to get the full picture, and that would answer your questions about the priority queues. And, you're welcome. smile.gif
Jules2009-11-10 02:36:27
Okay... So I've taken a few days off from Lusternia for health reasons (swine flu ftw!), and now I'm BACK!! ...to code... yay...

Anywho, I looked, Zarquan, at your coding and stuff, and I THINK I understand how you do the priority queueing... Make a Function that creates a list, and from this list, you add afflictions in order to cure from. Simple enough... I think... Am I right or off at all? I need a bunch of help with this, unfortunately...
Unknown2009-11-10 02:57:32
I borrowed the PHP table code from the Lua wiki, since non-numeric keys aren't guaranteed to be in any particular order in Lua tables normally. So, that's the first key to the priority curing.

You setup these ordered tables/lists of afflictions a priori, but they can be changed at any time and the curing will pick up on the new order right away (without the need for complex and inflexible if statements).

I just loop through the priority list for each balance and stop at the first one that comes up as a current affliction. There are lots of special little cases, however, that get handled through small manipulations of the priority queue and/or conditional statements, such as not curing horehound afflictions in Octave or not smoking an herb when you have asthma.