• How to have a array within a array
    10 replies, posted
hi i am having problems figuring out how to put an array within an array,for example the primary array should look something like this: [lua] array[1] = {name="Garry", ID="12983"} [/lua] so that you would be able to use [lua] for _,a in pairs(names) do if a.ID == steamid then Msg("Player Has Been Found In Records!\n") if a.name != ply:Name() then a.name = ply:Name() save_players_names() end Found = true end end [/lua] to separate the primary array into each individual array stored in side it and get the stored name and id
You can have infinite table keys. [lua] local examples = { andd = { more = { examples = { inside = { of = { a = { table = { "garry"; "please"; "add"; "binary"; "file"; "checksums"; }; }; }; }; }; }; }; }; local a = ""; for k, v in pairs( examples[ andd ][ more ][ examples ][ inside ][ of ][ a ][ table ] ) do a = a .. " " .. v; end; print( a ); [/lua] would output [quote] garry please add binary file checksums [/quote]
why wont this work: [lua] local temp_table = { ply = { username = "", userid="" } } temp_table[ply][userid] = string.gsub(c,"SteamID=","") [/lua] it goves me the error: "attempt to index field '?' (a nil value) " any ideas as to what is wrong?
You havnt set the variable 'c' as anything, the error is actually bad argument #1 to 'gsub' (string expected, got nil)
Actually, the problem is that he's defining a table incorrectly. Encase "ply" in square brackets when defining "temp_table". You want the value of ply to be the key, not the name "ply".
You can also do it this way : [lua]local temp_table = {} temp_table.ply = {1,45,64}[/lua]
That too
yay thanks for the help now another question when i input this string "EKS<@#$^&*>Dark<@#$^&*>Dragon" into this code [lua] local lame = string.gsub(c,"Name=","") Msg("Step 1 = "..lame) local lame2 = string.gsub(lame, "<@#$%^&*>", " ") Msg(" Step 2 = "..lame2) name = string.gsub(lame2,">*&^%$#@!<", "=") Msg(" Step3 = "..name.."\n") [/lua] c being the inputted string i get the exact same thing as i put in back out why?
I'm not sure but I think it's because your using the % in the second argument to gsub, so it's interpreting it as a pattern.
try using [lua]tostring("EKS<@#$^&*>Dark<@#$^&*>Dragon")[/lua]
If it's enclosed in ""'s it's a string, so no need to recast it.
Sorry, you need to Log In to post a reply to this thread.