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

How to read table codes without printing out the contents of the table?

Asked by 5 years ago

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?

0
if not its contents, then what are you trying to print? Gey4Jesus69 2705 — 5y
0
No im just wondering if you can read the table from the code 129Steve129 7 — 5y
0
print(table.concat(tbl, ", "))? User#25115 0 — 5y
0
Though, it's not that hard to loop through a table to print the contents, lol. User#25115 0 — 5y

1 answer

Log in to vote
4
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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!


References & Read-ups

Table dictionaries, Concatinating tables, Unpacking tables

0
You misspelled `local` EpicMetatableMoment 1444 — 5y
0
what is sep? 129Steve129 7 — 5y
0
the string to separate each value. for example, if you had a table like: local t = {"Hello","world!"} and you did: print(table.concat(t,",")), it would print "Hello, world!" Gey4Jesus69 2705 — 5y
0
you could also print an unpacked table theking48989987 2147 — 5y
Ad

Answer this question