Alias that cycle through commands

Post Reply
Guilend
Posts: 36
Joined: Fri Mar 09, 2018 1:21 am

Alias that cycle through commands

Post by Guilend »

I am very new to anything coding wise, and just started using Mudlet, but I am looking to something and I don't understand how to do it, I have looked through the forum, but since i havn't a clue as to what it is called, I couldn't find anything close.
I play Avalon, and my character is a Seer, we have curses, well, i don't want to have to remember what curse i should curse next all the time, so i want to make a, i am guessing a table, and add a list of the curses i want to use in a certain order, and then an alias that will cycle through this list as i enter the alias, but not send every curse on the list at the same time, or even on a timer, i want to control when the next curse is cast.
I do not know how to make a table, and i have tried looking it up on your mudlet manual, but sadly, it has gone over my head. if I can figure this out, it might just help me on the next thing i will be working on. Thanks for reading this, and I hope I made this understandable.

Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

Re: Alias that cycle through commands

Post by Jor'Mox »

So, to do this, you will need a table, and a variable to track your location in the table. Like this:

Code: Select all

local curses = {"curse 1","curse 2","curse 3"}
curse_index = curse_index or 1
send(curses[curse_index])
curse_index = curse_index + 1
if curse_index > #curses then curse_index = 1 end
This should create a table with all the commands you want to send, in order. It then makes a variable to track your position, and sends the command matching that position. After sending the command, it increases the tracking variable by one, and then checks to see if the tracking variable is too big, in which case it starts over at 1. You just need to change the values in the curses table to be whatever you need, making sure each command is surrounded in quotes, and separated by a comma.

Guilend
Posts: 36
Joined: Fri Mar 09, 2018 1:21 am

Re: Alias that cycle through commands

Post by Guilend »

Thank you so much, though at first I was not sure how to make it work, since the syntax for cursing is "curse " .. target .. " [curse]".
But with my limited knowledge of scripting, that I learned from using other's scripts, I managed to figure it out in less then 30 minutes lol.
I am really happy.

Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

Re: Alias that cycle through commands

Post by Jor'Mox »

Assuming that you have the name of your target in the "target" variable, one approach would be like this, which would conveniently allow you to use a variety of commands that may have a different syntax for each. To make it work, you just put the "%s" in wherever the target name is supposed to go, and the string.format call will perform the replacement for you.

Code: Select all

local curses = {"curse %s curse1","curse %s curse2","curse %s curse3"}
curse_index = curse_index or 1
send(string.format(curses[curse_index],target))
curse_index = curse_index + 1
if curse_index > #curses then curse_index = 1 end
But, I'm really glad you were able to figure it out for yourself, and that it is all working for you now.

Post Reply