1

Looking to get info from an array inside an array, without having exact info basically.

    local cfg_raids = {
    [2] =
    {
        ["10:17"] = {
            raidName = "Rats - Thais",
            Event_Type = "Raid Activated",
            Storage = 1234,
            alreadyExecuted = false
        },
        ["10:20"] = {
            raidName = "Testing this shit",
            Event_Type = "Raid Activated",
            Storage = 1235,
            alreadyExecuted = false
        },
    },
    [3] =
    {
        ["12:00"] = {
            raidName = "OrcsThais",
            Event_Type = "Raid Activated",
            Storage = 1236,
            alreadyExecuted = false
        },
    },

Trying to Grab the time randomly without actually having the exact time stamp.

So like when the script activates the timestamp array ["10:17"] it grabs all the next arrays info ["10:20"] without actually knowing the ["10:20"]

OPEN TIBIA INFORMATION: http://otland.net/threads/looking-for-some-assistance-on-a-script.216303/

1 Answer 1

2

With non-integer keys like that you can't really do it. You can try using the next function to get the next key from your current key but you have no guarantees which next key you will get if there are more than two keys in the table (you can not even guarantee that it will be consistently the same next key).

You could use integer indices in that table and make time a field of the table and then simply use the next integer as your next key if that works however.

You could also store the times used as keys, in whatever order you want, in the integer indices in the table (or some other table) and use that without needing to redo the table itself (e.g. cfg_raids = { [2] = { "10:17", "10:20", ["10:17"] = {...}, ["10:20"] = {...} } }).

Sign up to request clarification or add additional context in comments.

8 Comments

oh, thats what i kinda figured, too bad theres not a way to use like 0-10000 ect for calling the place, so you could use a for statement, thats the only thing i could think would of been really possible, but is there a way to do that?, like call the first, then the second, ect... places of an array / table
Hm? You can absolutely use a loop to walk a table index-by-index. Either manually for i = 1,#tab do ... end or using ipairs (for i, v in ipairs(tab) do ... end).
Tryed using both of those, still couldn't get them to read from the first posted table / array. for i,line in ipairs(cfg_raids) do pre_text = pre_text .. '\n '.. line end
The cfg_raids table in your original post is not an "array" in lua terms as it does not have contiguous keys from 1..n. As such ipairs is not, strictly, defined to operate over it. Also, your line variable there would contain a table not a string if it had been working. Try `local c = { {raidName = "raid 1"}, {raidName = "raid 2"} }; for i, raid in ipairs(c) do print(raid.raidName) end' just as an example.
@EtanReisner i'd suggest using pairs instead of ipairs, because the latter would stop at the first non-integer key, as it's designed for integer indexed arrays, while pairs is designed for any non-nil-indexed table.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.