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

How to cycle through Staffcast types

IyeIye Member Posts: 1
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
cecho("<orangered> SCINTILLA / FIRE CAST")
else if stafftype == scintilla then
cecho("<yellow> LIGHTNING / ELECTRIC CAST")
else if stafftype == lightning then
stafftype=horripilation then
cecho("<cyan> HORRIPILATION / ICE CAST")
else if stafftype == horripilation then
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!


  • JacenJacen Member Posts: 2,306 @@ - Legendary Achaean
    Need to put your lightning, dissolution, etc in quotes because they're strings

  • AntoniusAntonius Member Posts: 4,965 @@ - Legendary Achaean
    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)

    Then your alias just does:

  • IocunIocun Member Posts: 3,507 @@ - Legendary Achaean
    Just to make it even a tad more elegant, I'd replace
    staffcastIndex = (staffcastIndex == #staffcastTypes and 1) or (staffcastIndex + 1)

    staffcastIndex = staffcastIndex % #staffcastTypes + 1

    Give your pretty modulos a hug every day!
  • AntoniusAntonius Member Posts: 4,965 @@ - Legendary Achaean
    @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 to Comment.