1

# How do i print the whole table?

Edited 9 days ago

How do I print a whole table without making a mess? like this:

local exampleTable = {"Hello",  "Example", 1, 5}

print(exampleTable[1])
print(exampleTable[2])
print(exampleTable[3])
print(exampleTable[4])


this is the script:

local Decisions = {
"Left",
"Straight",
"Right"
}

local TablePrint = {}

for i = 1, 10, 1 do
local Randomizer = math.random(1,3)
table.insert(TablePrint, i, Decisions[Randomizer])
end

print(TablePrint)


it just prints: table: 0x7abaffbc3391dbd5 - Server - Script:4

What's the problem?

this piece of code by the way is to make a map for a maze so I don't have to decide.

the Script type is server-sided I'm also using Roblox Studios Run.

Any problem?

0
Edited 1 day ago

# Method 1: Using the (New) Output Window (Recommended)

It is likely that Log Mode is turned on in the Output window. Make sure to turn it off. Here is how:

1. Go to the three dots button at the top right of the Output window.
2. Make sure the Log Mode option is unchecked.
3. Play your game in Studio again. This time, the table and its contents will be printed in a nice format.

Here is a GIF of the first two steps I have mentioned above.

https://www.imgur.com/3k9gwO2

# Method 2: The "Old Way"

If you want to perhaps define your own format of printing tables, consider using a for loop, like this:

local Decisions = {
"Left",
"Straight",
"Right"
}

local TablePrint = {}

for i = 1, 10, 1 do
local Randomizer = math.random(1,3)
table.insert(TablePrint, i, Decisions[Randomizer])
end

-- Changes made start from here!
-- Go through each index and its corresponding element in TablePrint.
for index, decision in ipairs(TablePrint) do
-- Print each entry as specified in this format.
print(index .. ": " .. decision)
end


Note that this change only applies to tables that use numbers as indexes. However, I still recommend Method 1 because it eliminates the need to make those changes by using Studio's built-in tools.

If this answer solves your problem, make sure to accept it by clicking on the "Accept Answer" button. :)