Welcome to the Achaea Forums! Please be sure to read the Forum Rules.

[Lua] Table function

JonathinJonathin Grand Rapids, MIPosts: 3,197Member @@ - Legendary Achaean
edited February 2014 in Curing Systems and Scripts
I like to cycle arrays backward and forward and I do it so often, I wrote a function that does it, so I save a little bit of time.

p, li { white-space: pre-wrap; }

function cycletable(w,orig)

if w:lower() == "next" then

table.insert(orig,orig[1])

table.remove(orig,1)

elseif w:lower() == "previous" then

table.insert(orig, 1, orig[#orig])

table.remove(orig, #orig)

end

end


Usage is:
  cycletable("next", tablename) to cycle forward
and
  cycletable("previous", tablename) to cycle backward.

Because it's doing something funky to my formatting above, here is a pastebin.

(Mudlet Clan): Nylian says, "Mosr's on the case. Fix incoming."

Tutorials and scripts  The Repository

Tagged:

Comments

  • ShecksShecks Posts: 626Member ✭✭✭ - Distinguished

    I've never had to do this... Or if I did, I just used a backwards FOR loop.
    "Ignore the boos.  They usually come from the cheap seats."
    AntoniusStrata
  • CesarinaCesarina Posts: 125Member ✭✭✭ - Distinguished
    @Jonathin Can you give an example or 5 of what you'd use this for. I like efficient stuff but I can't think of what you'd need it for.
    -
    (Whiners Anonymous): Alcaro says, "If I overdose on anything, though, it'll be a lack of anything."
    (Whiners Anonymous): Alcaro says, "Isn't Morimbuul that Arab that was banished to beneath Mhaldor or something."
  • JonathinJonathin Grand Rapids, MIPosts: 3,197Member @@ - Legendary Achaean
    It's for things like a list of targets.

    targets = {"mosr", "cesarina", "shecks"} and it'll cycle forward and backwards through the list.

    I use it for things like ship weapon handling, targets, offence-type (1v1, gank, raid). I prefer to use this kind of thing rather than an alias because I can assign it to a macro and just cycle.

    (Mudlet Clan): Nylian says, "Mosr's on the case. Fix incoming."

    Tutorials and scripts  The Repository

Sign In to Comment.