[Lua] Table function

JonathinJonathin Retired in a hole.
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.
I am retired and log into the forums maybe once every 2 months. It was a good 20 years, live your best lives, friends.

Comments


  • I've never had to do this... Or if I did, I just used a backwards FOR loop.
  • @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 Retired in a hole.
    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.
    I am retired and log into the forums maybe once every 2 months. It was a good 20 years, live your best lives, friends.
Sign In or Register to comment.