Problem with table serialization

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Manyrio
Prole
Posts: 29
Joined: Sat Feb 06, 2016 10:12 am

Problem with table serialization

Post 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 !
function love.load() end
function love.update(dt) end
function love.draw() end
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Problem with table serialization

Post by Plu »

Unless you tell us what's wrong about the image you posted, I don't think we can really help you.
Manyrio
Prole
Posts: 29
Joined: Sat Feb 06, 2016 10:12 am

Re: Problem with table serialization

Post by Manyrio »

Yep sorry ^^

It make some horizontal shift like this :
Image
function love.load() end
function love.update(dt) end
function love.draw() end
User avatar
pgimeno
Party member
Posts: 3606
Joined: Sun Oct 18, 2015 2:58 pm

Re: Problem with table serialization

Post 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?
Manyrio
Prole
Posts: 29
Joined: Sat Feb 06, 2016 10:12 am

Re: Problem with table serialization

Post by Manyrio »

Yes no prb, here an exemple :
before :
Image
after :
Image
function love.load() end
function love.update(dt) end
function love.draw() end
User avatar
pgimeno
Party member
Posts: 3606
Joined: Sun Oct 18, 2015 2:58 pm

Re: Problem with table serialization

Post by pgimeno »

Can anyone else see a problem?
pedrosgali
Party member
Posts: 107
Joined: Wed Oct 15, 2014 5:00 pm
Location: Yorkshire, England

Re: Problem with table serialization

Post 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.

Code: Select all

if not wearTheseGlasses() then
  chewing_on_trashcan = true
end
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: Problem with table serialization

Post by Positive07 »

A .love file will be better to help you fix the issue

Or at least a map file
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
Manyrio
Prole
Posts: 29
Joined: Sat Feb 06, 2016 10:12 am

Re: Problem with table serialization

Post by Manyrio »

Thank you pedrosgali, I resolved the problem, it was exactly what you said.
function love.load() end
function love.update(dt) end
function love.draw() end
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests