MMOMinion

Full Version: table help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I need some help with the use of tables. I'm looking for a way to check if a value is in a table, and thought maybe there is a way without looping through the table? What I want to do is this (probably syntactically wrong):

Code:
function Summon.ClassCanSummon()
    local SummonerClasses {}
    SummonerClasses[1] = FFXIV.JOBS.SUMMONER
    SummonerClasses[2] = FFXIV.JOBS.ARCANIST
    if Player.classid is in SummonerClasses{} then
        return true
    end
    else
        return false
    end
end

so I build a table of jobs that can summon, and want to check if the players class is in that table, and then return a true/false.

Edit: I solved it by not using a table, isn't worth it for two values, I guess ;)
You could have done this so much simpler...

For example (first reply):
http://stackoverflow.com/questions/22824...ent-in-lua

SummonerClasses[FFXIV.JOBS.SUMMONER] = true
SummonerClasses[FFXIV.JOBS.ARCANIST] = true

if (SummonerClasses[myClass] ~= nil) then (summoner/arcanist)...
else (the rest) ...
nice... I'm still trying to get along with LUA ;) I used this now:

if (Player.job == FFXIV.JOBS.SUMMONER or Player.job == FFXIV.JOBS.ARCANIST) then
return true
end
Even then, do yourself a favor and do return Player.job == X or Player.job == y, saves a whole line! :D
Code:
function Summon.ClassCanSummon()
    if (Player.job == 26 or Player.job == 27) then
        return true
    end

    return false
end

or

Code:
function Summon.ClassCanSummon()
    return (Player.job == 26 or Player.job == 27)
end
(10-30-2013, 02:57 PM)KaWeNGoD Wrote: [ -> ]
Code:
function Summon.ClassCanSummon()
    return (Player.job == 26 or Player.job == 27)
end

from what I've read here https://github.com/MMOMinion/FFXIVMinion...umerations it is recommended to use the Enumerations (since the result could change with a patch)