Page 1 of 1

Strange index problem.[Solved]

Posted: Mon Aug 15, 2022 1:22 pm
by NoreoAlles
When executing my level creation code i get this strange error:
"Error

Syntax error: src/level.lua:8: unexpected symbol near '='
"

My Code looks like this

Code: Select all

Level = {}
Level.__index = Level

function Level.new(x, y, map_width, map_height,tile_width , tile_height, image, tiles, collision, entities) 
    local instance = setmetatable({}, Level) 
    instance.x = x
    instance.y = y 
    instance.map = {}
    instance.map.width = map_width 
    instance.map.height = map_height
    instance.map.tile_width = tile_width 
    instance.map.tile_height = tile_height
    instance.map.tiles = tiles
    instance.map.spritbatch = love.graphics.newSpriteBatch(image)
    instance.map.image = image
    instance.map.quads = {}
    for y=0, instance.map.image:getWidth() / instance.map.tile_height do 
        for x=0, instance.map.image:getHeight() / instance.map.tile_width do 
            q = love.graphics.newQuad((x-1)*instance.map.tile_width, (y-1)*instance.map.tile_height, instance.map.tile_height, instance.map.tile_width, instance.map.image.getWidth(), instance.map.image.getHeight())
            table.insert(instance.map.quads, q)
        end
    end
    for y, xs in ipairs(instance.map.tiles) do 
        for x, value in ipairs(xs) do 
            instance.map.spriteBatch:add(instance.tile.quads[instance.map.table[y][x]], ( x-1) * instance.map.tile_width, (y-1) * instance.map.tile_height )
        end
    end
    return instance
end

function Level:draw()
    love.graphics.draw(self.spritbatch)
end

Re: Strange index problem.

Posted: Mon Aug 15, 2022 1:25 pm
by GVovkiv
I'm not Sherlock, but, probably, problem lies under "src/level.lua" at line 8.
Where this "src/level.lua"?
Where main.lua?
Can you post .love file with all necessery to reproduce problem files?

Re: Strange index problem.

Posted: Mon Aug 15, 2022 1:35 pm
by NoreoAlles
Woops, found the problem, i had two files name "level.lua". One of wich had a syntax error at line 8. :ultrahappy: