aTable = {"data","data","something else"}
i just want "aTable" as a string instead of a table so when I do print() it returns "aTable" instead of table: (random letters)
aTable = {"data","data","something else"}
aTbl = textutils.serialize(aTable)
print(aTbl)
Well..aTbl = textutils.serialize(aTable)
print(aTbl)
That just returns the data in the table :P/>/>
local function getTableName(tbl)
for k, v in pairs(_G) do
if v == tbl then
return k
end
end
return nil
end
someTable = {}
print(getTableName(someTable))
Very bad thing to do, but it should work.Well..aTbl = textutils.serialize(aTable)
print(aTbl)
That just returns the data in the table :P/>/>
print(aTable[1])
or
aTable = {test = "String" }
print(aTable.test)
When you print table, you have to do it in a loop for all values or just print those single values.Well..aTbl = textutils.serialize(aTable)
print(aTbl)
That just returns the data in the table :P/>/>
print(aTable[1])
or
aTable = {test = "String" }
print(aTable.test)
Well I guess I could just add to all my tables aTable {Name = "tablename"} but is there no other shorter way?
No there's no way to get the table name, because when compiled to bytecode the name is not used anymore. But, if that table is global (or inside another table) you can do it by comparing it to each value in _G (or whatever table it's stored in).
Example:Very bad thing to do, but it should work.local function getTableName(tbl) for k, v in pairs(_G) do if v == tbl then return k end end return nil end someTable = {} print(getTableName(someTable))
What do you even need this for? There might be a better way to do it.
function Array_SAVE(FileName, ARRAY)
local collection = ""
for i=1, #ARRAY do
if i==1 then
collection = (collection..[["]]..ARRAY[i]..[["]])
else
collection = (collection..", "..[["]]..ARRAY[i]..[["]])
end
end
local file = io.open(FileName,"w")
file:write(FileName.." = {"..collection.."}")
file:close()
end
Well, I think it's better to do it that way (passing the name and the table). Also, you should try using textutils.serialize and unserialize, it will make it easier to save and then load.