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?
It is likely that Log Mode is turned on in the Output window. Make sure to turn it off. Here is how:
Here is a GIF of the first two steps I have mentioned above.
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. :)