Page 1 of 1

Problem with table serialization

Posted: Wed Jul 13, 2016 7:49 pm
by Manyrio
Hey,
I have problem while loading (or saving, I don't really know) my map, it does things like these :
Image
here's the code :

Code: Select all

-- this is for import map to string
function map2string(maptable,typeser)
  local sz = ''
  for y = 0, map.height do
    local row = {}
    for x = 0, map.width do
      local c = typeser[maptable[x][y]]
      c = (c ~= nil) and c or ' '
      if not tostring(c):len() == 1 then
        error("non-ANSI character on:" .. x .. ',' .. y)
      end
      row[x] = c
    end
    sz = sz .. table.concat(row) .. '\n'
  end
  return sz
end
-- this is for import string to map
local x, y = 0, 0
for l in string.gmatch(love.filesystem.read(file), "(.-)\n") do
  for c in string.gmatch(l, ".") do
    if map_signloader[c] ~= "nil" and x < map.width+1 then
      map_level[x][y] = map_signloader[c]
    end
    x = x + 1
  end
  x, y = 0, y + 1
end
Hope you can help me !

Re: Problem with table serialization

Posted: Wed Jul 13, 2016 8:33 pm
by Plu
Unless you tell us what's wrong about the image you posted, I don't think we can really help you.

Re: Problem with table serialization

Posted: Thu Jul 14, 2016 11:02 am
by Manyrio
Yep sorry ^^

It make some horizontal shift like this :
Image

Re: Problem with table serialization

Posted: Thu Jul 14, 2016 1:43 pm
by pgimeno
I can see nothing wrong in the new image either. What horizontal shift? Can you maybe take gimp or something, and produce an image of how it should look like, and how it actually looks like?

Re: Problem with table serialization

Posted: Thu Jul 14, 2016 2:10 pm
by Manyrio
Yes no prb, here an exemple :
before :
Image
after :
Image

Re: Problem with table serialization

Posted: Thu Jul 14, 2016 7:48 pm
by pgimeno
Can anyone else see a problem?

Re: Problem with table serialization

Posted: Thu Jul 14, 2016 8:05 pm
by pedrosgali
I think the problem is with counting from 0 to map.width instead of map.width - 1, it thinks the map is one wider than it is so the first block of row 2 is on the end of line 1. After a few lines the map would look very different. This is a total guess though, not a lot of info to go on here.

Re: Problem with table serialization

Posted: Fri Jul 15, 2016 9:26 pm
by Positive07
A .love file will be better to help you fix the issue

Or at least a map file

Re: Problem with table serialization

Posted: Sat Jul 16, 2016 10:55 am
by Manyrio
Thank you pedrosgali, I resolved the problem, it was exactly what you said.