I was asked on the Mudlet discord channel to post some of my scripts, so this is just a couple, all of my scripts follows this same pattern since it's the only way I have learned to script at the moment. This is probably the most simplest script to most of you, but I didn't know how to script and still really don't. I had asked someone to send me a script for my charming spells on the MUD I play, Avalon The Legend lives. He sent me this one first.
function charmingSpell(spell, spellTarget)
send("chant " .. spell)
if spellTarget then
send("cast " .. spellTarget)
elseif target then
send("cast " .. target)
else
send("cast")
end
end
With this you can cast spells at someone else, like a friend, or yourself, or at your target. With this one script I learned a lot about scripting with "if,elseif and else" commands. This one I wrote for poisons.
function PoisonSS(PoiS, SpiTT)
if SpiTT then
send("outp " .. PoiS .. " spit " .. PoiS " at " .. target)
else
send("rub " .. PoiS .. " on knife;stab " .. target)
end
end
With this I can either spit or stab poisons at my target.
Doing more with one alias.
Re: Doing more with one alias.
Just as a useful note, when posting code to the forums, it is useful to use a tag to indicate that the text to follow is code, or more specially lua code. To do this, you start by using this tag with the spaces removed: [ lua ] , and you close out that block of text with this tag, again with the spaces removed: [ /lua ]
It makes it look like this, which is much easier to read:
It makes it look like this, which is much easier to read:
Of course, this doesn't help if the code itself isn't properly indented, like in your second example, but it is a step in the right direction regardless.
Re: Doing more with one alias.
Thanks, I was wondering how others did that lol
Re: Doing more with one alias.
Since you are new to all this, here is some feedback on the functions you posted.
Firstly, here is just a nicely formatted version of your second function:
You can also use "or" and "and" operators to combine things together to make logic a bit simpler, such as in your first function, which could be changed like this:
Firstly, here is just a nicely formatted version of your second function:
One obvious issue here is that you are missing a concatenation symbol (the '..') in your first send line, right after the second PoiS. But, you can make all of that a bit simpler to manage by using the string.format function like this:
Using string.format, each instance of %s is replaced with the corresponding variable or value, which makes it much easier to avoid forgetting spaces or concatenations, etc, and is generally just a bit easier to read.
You can also use "or" and "and" operators to combine things together to make logic a bit simpler, such as in your first function, which could be changed like this:
I added some comments to the code here to help explain what each of the different steps is doing. While this isn't significantly simpler than your original version, I think it provides a useful example to help illustrate how you can use 'or' and 'and'. Realistically, I would probably use a version like this:
Re: Doing more with one alias.
wow thanks. Yeah,I have just now started to figure out how to make the lua format on here. Thanks for making it look better for me and thanks for you wonderful advice and teaching me newt things, you are the best.