Search code examples
luacs50love2dpong

Error with push.lua from CS50 game course


I have a problem with the folder "pong-1" that contains "main.lua" and "push.lua". When I select them into "LÖVE", it says:

>Error
push.lua:71: bad argument #1 to 'insert' (table expected, got number)
[C]: in function 'insert'
push.lua:71: in function 'setupCanvas'
main.lua:12: in function 'load'
[C]: in function 'xpcall'
[C]: in function 'xpcall'

I tried with the outdated version of push.lua (which offers the source code of the course) as well as the newest version I could find, but neither of them worked. Both display the same error message. What could be the problem?


Solution

  • function push:setupCanvas(canvases)
      table.insert(canvases, { name = "_render", private = true }) --final render
    
      self._canvas = true
      self.canvases = {}
    
      for i = 1, #canvases do
        push:addCanvas(canvases[i])
      end
    
      return self
    end
    

    This functions expects canvases to be a table value.

    You provide a number value VIRTUAL_WIDTH in your function call

    push:setupCanvas(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, WINDOW_WIDTH,
      WINDOW_HEIGHT,{ fullscreen = false, resizable = false, vsync = true })
    

    instead.

    Looks like you're confusing setupCanvas with setupScreen