pielago wrote:Omg thank you so much i tried to fix it and didn't know where the problem was
i am able now to save even X,Y pos
question will this work if i want to save tables? or many tables? or do i need another way ????
and thank you for your reply great forum..
You're welcome!
Saving tables IS possible, but not easy. You'd have to do something like this:
Code: Select all
local txt = ""
local splitchar = "/"
for i, v in pairs(table) do
txt = txt .. tostring(v) .. splitchar
end
txt = string.sub(txt, 1, -2)
But if you've got something (a string for example) in that table that contains the "splitchar" part, replace it by something else.
Also, things may go weird if you have tables inside tables. To load, you must use the "string:split()" function. I'll already let clear that it
was not made by me:
Code: Select all
function string:split(delimiter) --Not by me
local result = {}
local from = 1
local delim_from, delim_to = string.find( self, delimiter, from )
while delim_from do
table.insert( result, string.sub( self, from , delim_from-1 ) )
from = delim_to + 1
delim_from, delim_to = string.find( self, delimiter, from )
end
table.insert( result, string.sub( self, from ) )
return result
end
And while loading:
Code: Select all
table = {}
local t = textlaoded:split(splitchar)
for i, v in pairs(t) do
if tonumber(v) then
table.insert(table, tonumber(v))
elseif v == "true" then
table.insert(table, true)
elseif v == "false" then
table.insert(table, false)
else
table.insert(table, v)
end
end
But that depends
a lot on how your table is and what it contains. I'd not use it if you have different things on your table, or if your table have custom items (like table["string"] or table.string - which is the same thing, but still).