Strange index problem.[Solved]

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
User avatar
NoreoAlles
Party member
Posts: 107
Joined: Mon Jan 03, 2022 5:42 pm

Strange index problem.[Solved]

Post 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
Last edited by NoreoAlles on Mon Aug 15, 2022 1:37 pm, edited 1 time in total.
"Why do they call it oven when you of in the cold food of out hot eat the food?" - Jon Arbuckle
User avatar
GVovkiv
Party member
Posts: 668
Joined: Fri Jan 15, 2021 7:29 am

Re: Strange index problem.

Post 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?
User avatar
NoreoAlles
Party member
Posts: 107
Joined: Mon Jan 03, 2022 5:42 pm

Re: Strange index problem.

Post by NoreoAlles »

Woops, found the problem, i had two files name "level.lua". One of wich had a syntax error at line 8. :ultrahappy:
"Why do they call it oven when you of in the cold food of out hot eat the food?" - Jon Arbuckle
Post Reply

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot] and 49 guests