Thread Rating:
  • 8 Vote(s) - 2.75 Average
  • 1
  • 2
  • 3
  • 4
  • 5
table help
#1
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 ;)
Reply
#2
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) ...
Frankly, my dear, I don't give a damn...
Reply
#3
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
Reply
#4
Even then, do yourself a favor and do return Player.job == X or Player.job == y, saves a whole line! :D
Frankly, my dear, I don't give a damn...
Reply
#5
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
Reply
#6
(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)
Reply
 


Forum Jump:


Users browsing this thread: 5 Guest(s)

We help you win the game.

FFXIV Bot and More.

 

Products