Migrating from CMud and looking for design patterns
Posted: Mon Jul 10, 2017 9:12 pm
Hi,
I'm about a week into using Mudlet and loving it so far. I'm in the process of trying to move my scripts and bots from CMud over so that's driving much of my learning.
One thing I'm trying to figure out is what are my options for porting CMud code like this contrived example:
I've read Time Engine wiki page so I am aware that there is no equivalent to #WAIT available in Mudlet. I've already ported some code over and used tempTrigger() to accomplish some goals. However, in a lot of my CMud bots/scripts it's not at all rare that I have a piece of code like the above, but much longer and more complex. Porting all of these and nesting tempTrigger()'s seems to make maintenance of said code more painful.
One thing I have started doing is breaking these code blocks up into multiple functions and chaining them together with tempTrigger() to accomplish something similar to the original code without nesting quoted tempTimer() blocks:
This appears to be the best (i.e., readable and easy to modify and maintain) solution I can come up with at the moment.
My question to the more experienced Mudlet users: are there some common patterns for tackling this sort of code that will make it easier to read, develop, and maintain?
I'm about a week into using Mudlet and loving it so far. I'm in the process of trying to move my scripts and bots from CMud over so that's driving much of my learning.
One thing I'm trying to figure out is what are my options for porting CMud code like this contrived example:
Code: Select all
get all sack
#WAIT 2000
drop all.sword
#WAIT 2000
#ECHO "done"
One thing I have started doing is breaking these code blocks up into multiple functions and chaining them together with tempTrigger() to accomplish something similar to the original code without nesting quoted tempTimer() blocks:
Code: Select all
TEST = TEST or {}
function TEST.test()
fg("cyan")
echo("\nTEST.test()\n")
TEST.test1()
end
function TEST.test1()
echo("TEST.test1()\n")
tempTimer(2, [[TEST.test2()]])
end
function TEST.test2()
echo("TEST.test2()\n")
tempTimer(2, [[TEST.test3()]])
end
function TEST.test3()
echo("TEST.test3()\n")
end
My question to the more experienced Mudlet users: are there some common patterns for tackling this sort of code that will make it easier to read, develop, and maintain?