How to cycle through Staffcast types

I'm not good with Lua (basic stuff even doesn't work sometimes)

Just wondering the easiest way to use an alias or a keybinding to cycle through different options for a variable (in this cast stafftype...or something)

this is off the top of my head, but I would like to know if I'm close...or if there's anything else I can do:

if stafftype == dissolution then
stafftype=scintilla
cecho("<orangered> SCINTILLA / FIRE CAST")
else if stafftype == scintilla then
stafftype=lightning
cecho("<yellow> LIGHTNING / ELECTRIC CAST")
else if stafftype == lightning then
stafftype=horripilation then
cecho("<cyan> HORRIPILATION / ICE CAST")
else if stafftype == horripilation then
stafftype=dissolution
cecho("<greenyellow> DISSOLUTION / MAGIC CAST")


And my alias for staffcast would be something like:

send ("staffcast "..stafftype.." at "..target)

Any advice (or a code fix :P) would be incredible. Thanks!

Comments

  • Need to put your lightning, dissolution, etc in quotes because they're strings

    image
  • edited January 2014
    I'd personally do something like this:

    local staffcastTypes = {"dissolution", "scintilla", "lightning", "horripilation"}
    local staffcastIndex = 1

    function staffcast()
        send("staffcast " .. staffcastTypes[staffcastIndex] .. " at " .. target)
        staffIndex = (staffcastIndex == #staffcastTypes and 1) or (staffcastIndex + 1)
    end

    Then your alias just does:

    staffcast()
  • Just to make it even a tad more elegant, I'd replace
    staffcastIndex = (staffcastIndex == #staffcastTypes and 1) or (staffcastIndex + 1)

    with:
    staffcastIndex = staffcastIndex % #staffcastTypes + 1


    Give your pretty modulos a hug every day!
  • @Iocun: I've gotten used to Lua not having nice things so didn't want to risk untested use of a modulo. Also changing variable names (staffIndex to staffcastIndex) after writing code is never a good idea...
Sign In or Register to comment.