When you do print({"yourtable"}) it prints out a code like table: 2673D9D0 is there any way you can read tables this way without having to print out all of whats inside a table?
If you'd like to view all the contents inside of your array without having to stream through its contents using a for loop, simply use the table.concat(tab, sep)
, or unpack(tab)
function. Usually, these sorts of loops are indented for use of comparing or analyzing elements of a table.
sep
is an optional separation argument between each element of a table, this can only be represented by Characters. For instance. I if I separate by ', '
, the concatenated elements would be presented like so:
local rawtable = {"Hi","there!"} print(table.concat(rawtable, ", ")) --// -> Hello, there!
For unpack
, it will return all the tables elements with an unamendable, predefined separation. I still suggest using table.concat
as unpack
would be used in other scenarios. Yet it's primarily based off of your preference, and where & when to use it. Applying unpack
would be presented like so:
local rawtable = {"Hi","there!"} print(unpack(rawtable)) --// -> Hi there! --// Interesting use of unpack() local rawtable = {"Hi","there!"} local a,b = unpack(rawtable) --// returns first element to a, second to b. print(a,b) --// -> Hi there!
I honestly don't understand why Lua spits out tables in this format. Though it will return the desired value alone in a proper, readable format. To get that value, you can index it's numerical position in the table
local rawtable = {1, 2, 3}; print(rawtable[2]) --// -> 2
Don't mistake this for printing the exact value in the table matched in []
. Again, the number two sit's at the numerical index of 2 inside the table, as it's the second element from the first.
Though if you'd like to have this done, you could use create a dictionary index.
local rawtable = { ["mystring"] = "Hello there!" --// 'mystring' is a dictionary index, think of it as a reference. }; print(rawtable["mystring"]) --// -> Hello there!
This may be quite hard to gather, though may not be too. If there's anything you'd like me to further interpret please ask.
Don't forget to accept and upvote if this helps!
• Table dictionaries, Concatinating tables, Unpacking tables