Creating a quad loop (somethings wrong?)

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
crystalheartstudios
Prole
Posts: 10
Joined: Thu Sep 04, 2014 7:38 pm

Creating a quad loop (somethings wrong?)

Post by crystalheartstudios »

Alright I'm at my wits end. I'm attempting to use ipairs in a for loop to help simplify my quad declarations, but something is wrong. I'm actually following a guide, and at first I attempted to write the code myself, but after several hours of errors, I tried copying and pasting the code, and for some reason it still isn't working. My code is below:

Code: Select all


Tileset = love.graphics.newImage('images/dg_edging132.gif') --- Tileset
  Tree = love.graphics.newImage('images/tree1.png')
  
  TileW, TileH = 32,32 --- Determine length and width of every tile (32 in this case)
  local tilesetW, tilesetH = Tileset:getWidth(), Tileset:getHeight() --- Determines length and width of entire tileset
  
  local quadInfo = {
  	{0, 0}, -- 1 (Left Corner)
  	{32, 0}, -- 2 (Top Shore)
  	{96, 0}, -- 3 (Right Corner)
  	{96, 32}, -- 4 (Right Shore)
  	{0, 32}, -- 5 (Left Shore)
  	{0, 96}, -- 6 (Left Bottom Corner)
  	{32, 480}, -- 7 (Solid Grass)
  	{32, 96}, -- 8 (Bottom Shore)
  	{96, 96}, -- 9 (Right Bottom Corner)
  	{32, 64}, -- 10 (Bottom Right Curve)
  	{64, 64}, -- 11 (Bottom Left Curve)
  	{32, 32}, -- 12 (Top Right Curve)
  	{64, 32} -- 13 (Top Left Curve)
  
  }
  
  Quads = {}
    for i,info in ipairs(quadInfo) do
    -- info[1] = x, info[2] = y
    Quads[i] = love.graphics.newQuad(info[1], info[2], TileW, TileH, tilesetW, tilesetH)
  end

  TileTable = { --- Edit this to design level
  {1,2,2,2,2,3,1,2,2,2,2,3,1,2,2,2,2,2,3,1,2,2,2,2,3},
  {5,7,7,7,7,4,5,7,7,7,7,4,5,7,7,7,7,7,4,5,7,7,7,7,4},
  {5,7,7,7,7,4,5,7,7,7,7,4,5,7,7,7,7,7,4,5,7,7,7,7,4},
  {5,7,7,7,7,4,5,7,7,7,7,4,5,7,7,7,7,7,4,5,7,7,7,7,4},
  {5,7,7,7,7,4,5,7,7,7,7,4,5,7,7,7,7,7,4,5,7,7,7,7,4},
  {5,7,7,7,7,10,11,7,7,7,7,10,11,7,7,7,7,7,10,11,7,7,7,7,4},
  {5,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,4},
  {5,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,4},
  {5,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,12,13,7,7,7,7,4},
  {5,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,4,5,7,7,7,7,4},
  {5,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,4,5,7,7,7,7,4},
  {5,7,7,7,7,7,7,7,7,7,7,12,13,7,7,7,7,7,4,5,7,7,7,7,4},
  {5,7,7,7,7,7,7,7,7,7,7,4,5,7,7,7,7,7,4,5,7,7,7,7,4},
  {5,7,7,7,7,7,7,7,7,7,7,4,5,7,7,7,7,7,4,5,7,7,7,7,4},
  {5,7,7,7,7,7,7,7,7,7,7,4,5,7,7,7,7,7,10,11,7,7,7,7,4},
  {5,7,7,7,7,7,7,7,7,7,7,4,5,7,7,7,7,7,7,7,7,7,7,7,4},
  {5,7,7,7,7,7,7,7,7,7,7,10,11,7,7,7,7,7,7,7,7,7,7,7,4},
  {5,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,4},
  {6,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,9},
  
}

User avatar
DaedalusYoung
Party member
Posts: 413
Joined: Sun Jul 14, 2013 8:04 pm

Re: Creating a quad loop (somethings wrong?)

Post by DaedalusYoung »

Do you get any errors? What's the rest of the code? You have no callbacks defined, so just this code won't do anything visible.
crystalheartstudios
Prole
Posts: 10
Joined: Thu Sep 04, 2014 7:38 pm

Re: Creating a quad loop (somethings wrong?)

Post by crystalheartstudios »

Oh I apologize I do get an error. It is:

Code: Select all

Syntax error: main.lua:71: 'do' expected near 'in'


Traceback
[C]: at 0xb74fc610
[C]: in function 'require'
[C]: in function 'xpcall'


User avatar
DaedalusYoung
Party member
Posts: 413
Joined: Sun Jul 14, 2013 8:04 pm

Re: Creating a quad loop (somethings wrong?)

Post by DaedalusYoung »

What's on line 71?
crystalheartstudios
Prole
Posts: 10
Joined: Thu Sep 04, 2014 7:38 pm

Re: Creating a quad loop (somethings wrong?)

Post by crystalheartstudios »

for rowIndex=1,row in ipairs(TileTable) do
crystalheartstudios
Prole
Posts: 10
Joined: Thu Sep 04, 2014 7:38 pm

Re: Creating a quad loop (somethings wrong?)

Post by crystalheartstudios »

I guess it would help to post the rest of the for loop:

Code: Select all


function love.draw()
  for rowIndex=1,row in ipairs(TileTable) do --- Determines Row (For loop moves down the rows)
    for columnIndex=1,number in ipairs(row) do --- Runs through columns based on every row
      local x,y = columnIndex-1)*TileW, (rowIndex-1)*TileH --- Determines the coordinates of the particular tile
      love.graphics.draw(Tileset, Quads[number], x, y) --- Draws the found tile
    end
  end
end

User avatar
DaedalusYoung
Party member
Posts: 413
Joined: Sun Jul 14, 2013 8:04 pm

Re: Creating a quad loop (somethings wrong?)

Post by DaedalusYoung »

Code: Select all

for rowIndex=1,row in ipairs(TileTable) do
should be something like

Code: Select all

for rowIndex, row in ipairs(TileTable) do
Also, you're missing a parenthesis in the line

Code: Select all

local x,y = columnIndex-1)*TileW, (rowIndex-1)*TileH
crystalheartstudios
Prole
Posts: 10
Joined: Thu Sep 04, 2014 7:38 pm

Re: Creating a quad loop (somethings wrong?)

Post by crystalheartstudios »

Well that worked! Thanks so much!
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 3 guests