ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   tables and string.find help (https://www.esoui.com/forums/showthread.php?t=10546)

sinnereso 05/19/23 10:49 AM

tables and string.find help
 
hey guys,

Im messing around with tables for a new feature mostly to understand these better and I hit a wall. I keep getting nil as a returned value and I cant see why.

Code:

function MyAddon.FakeFunction()
    MyAddon.savedVariables.autoMetSwap = "Master Gatherer"
    local swapSkill = MyAddon.FindChampionSwapSkill()
    df(tostring(swapSkill))
end

function MyAddon.FindChampionSwapSkill()
        --/script  df(GetChampionSkillName(number))
        local championSkills = {
                ["Master Gatherer"] = 78,
                ["Treasure Hunter"] = 79,
                ["Gifted Rider"] = 92,
                ["Homemaker"] = 91,
                ["Cutpurse's Art"] = 90,
                ["Infamous"] = 77,
                ["Reel Technique"] = 88,
                ["Angler's Instincts"] = 89,
                ["Steed's Blessing"] = 66,
                ["Sustaining Shadows"] = 65,
        }
        for skillName, skillID in ipairs(championSkills) do
                if string.find(MyAddon.savedVariables.autoMetSwap, skillName, 1, true) ~= nil then
                        return skillID
                end
        end
end

I'm wanting the function to return the skillID into the swapSkill variable at the top but its returning nill nomatter what I do.

Masteroshi430 05/19/23 12:41 PM

Quote:

Originally Posted by sinnereso (Post 47798)
hey guys,

Im messing around with tables for a new feature mostly to understand these better and I hit a wall. I keep getting nil as a returned value and I cant see why.

Code:

function MyAddon.FakeFunction()
    MyAddon.savedVariables.autoMetSwap = "Master Gatherer"
    local swapSkill = MyAddon.FindChampionSwapSkill()
    df(tostring(swapSkill))
end

function MyAddon.FindChampionSwapSkill()
        --/script  df(GetChampionSkillName(number))
        local championSkills = {
                ["Master Gatherer"] = 78,
                ["Treasure Hunter"] = 79,
                ["Gifted Rider"] = 92,
                ["Homemaker"] = 91,
                ["Cutpurse's Art"] = 90,
                ["Infamous"] = 77,
                ["Reel Technique"] = 88,
                ["Angler's Instincts"] = 89,
                ["Steed's Blessing"] = 66,
                ["Sustaining Shadows"] = 65,
        }
        for skillName, skillID in ipairs(championSkills) do
                if string.find(MyAddon.savedVariables.autoMetSwap, skillName, 1, true) ~= nil then
                        return skillID
                end
        end
end

I'm wanting the function to return the skillID into the swapSkill variable at the top but its returning nill nomatter what I do.

df(tostring(swapSkill)) -> d(tostring(swapSkill)) maybe?

sinnereso 05/19/23 12:56 PM

nope doesnt work either... I've even put a chat output inside the:

Code:

for skillName, skillID in ipairs(championSkills) do
                df(tostring("HELLO"))

and its not outputting so something wrong with the for statement but its looks perfect to me. In other examples most people use _ dummy for skillName but in my case I want that info. Does it need to be a number or index or can it be strings like I have there?

OR... theres something wrong with how im calling the function with:

Code:

local swapSkill = MyAddon.FindChampionSwapSkill()
im googling now on calling functions but I'm pretty sure this is fine as well

sinnereso 05/19/23 01:24 PM

makes no sense to me.. HELLO outputs fine everytime.. HELLO 2 not even once ever. I even tried reversing the names and ID's like this.

Code:

function MyAddon.FindChampionSwapSkill()
        --/script  df(GetChampionSkillName(number))
        df("HELLO")
        local championSkills = {
                [78] = "Master Gatherer",
                [79] = "Treasure Hunter",
                [92] = "Gifted Rider",
                [91] = "Homemaker",
                [90] = "Cutpurse's Art",
                [77] = "Infamous",
                [88] = "Reel Technique",
                [89] = "Angler's Instincts",
                [66] = "Steed's Blessing",
                [65] = "Sustaining Shadows",
        }
        for skillID, skillName in ipairs(championSkills) do
                df("HELLO 2")
                if string.find(tostring(MyAddon.savedVariables.autoMetSwap), tostring(skillName), 1, true) ~= nil then
                        return tonumber(skillID)
                end
        end
end


Baertram 05/19/23 03:01 PM

Ipairs does not work with non indexed, non gap table keys like strings are!
Use pairs

Ipairs only works if table is an array like key 1,2,3,4,...without any gap in between

sinnereso 05/19/23 03:11 PM

Yeh I think Ive figure that out.

Now im trying to use string.find to find "Someplace" in example("Someplace 88").

and then later to find the "88" and save the 88 to a variable.

* just realized you said use pairs.. ill try it

sinnereso 05/19/23 03:51 PM

Quote:

Originally Posted by Baertram (Post 47805)
Ipairs does not work with non indexed, non gap table keys like strings are!
Use pairs

Ipairs only works if table is an array like key 1,2,3,4,...without any gap in between

OMG ty! that worked perfectly :)

Baertram 05/20/23 06:15 AM

yw.

btw, why don't you use the IDs of the champion skills instead of the names? Again this will be complicating everything if you try to search and compare strings with multi language games.
You really should rethink your learning curve and check if there are IDs (numbers) to use instead of strings. Once you learned that you never will fallback to strings anymore, and it will be less complicative ;)

sinnereso 05/20/23 03:35 PM

YA i do agree with you but I dont feel im ready yet to even consider other languages etc. Thats going to be my final thing down the road.


All times are GMT -6. The time now is 06:58 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI