Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Table does not working with table.find condition?

Asked by 4 years ago

Hi, i have make a list of a boss in my server, when a player attack a boss i want to check if the specific boss is in the list, i have make this:

local list = {
    "Fox",
    "Yeti",
    "Crocodile",
    "Pharaoh"
}

When the player attack the boss i have this condition:

if table.find(list, HitParent) then
    print("Rangeboss")

HitParent = the name of the boss when the player attack, so for exemple HitParent = Fox

But the print is’nt fire ^^ maybe my condition is not exactly, somebody have a solution for check the name of the boss in the list ?

1
It's probably not the table.find part, maybe it's something else with your code? Try posting the whole thing so we can check if there's an error somewhere that's causing it to not print. killerbrenden 1537 — 4y

3 answers

Log in to vote
1
Answered by
Nckripted 580 Moderation Voter
4 years ago

Use a for loop to search if the item is in the array. For example, you can do something like this:

for i,v in pairs (list) do
    if v == hitParent then
        print("Hit boss")
    end
end

Hope this helped!

0
Not Working, the print isn't fire :/ Thorngard 4 — 4y
0
for i,v in pairs (list) do if v == hitParent then print("Hit boss") else print("Not on the list") end end AlexTheCreator 461 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

for this to work, HitParent must be a string value and you can do this:

for i,v in pairs(list) do
    if v == HitParent then
        print"hello"
    end
end
0
also table.find() does not exist in lua floppybeann 0 — 4y
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

if list[HitParent] then print(HitParent) end

Answer this question