'Love2d "bad argument #2 to 'draw' (Quad expected, got nil)"

I am currently trying to make a flappy bird copy and I am having trouble when attempting to spawn in pipes (when a pipe should spawn I get the following error: "bad argument #2 to 'draw' (Quad expected, got nil)").

The functions that are causing the problem are the following (they are located in three different classes):

Pipe = Class{}

local PIPE_IMAGE = love.graphics.newImage('FlappyBirdPipe.png')

PIPE_SCROLL = -60

PIPE_WIDTH = 20
PIPE_HEIGHT = 160

function Pipe:init(orientation, y)
    self.x = VIRTUAL_WIDTH
    self.y = y

    self.width = PIPE_IMAGE:getWidth()
    self.height = PIPE_HEIGHT

    self.orientation = orientation
end

function Pipe:render()
    love.graphics.draw(PIPE_IMAGE, self.x, 
        (self.orientation == 'top' and self.y + PIPE_HEIGHT or self.y),
        0, 1, (self.orientation == 'top' and -1 or 1))
end
function PipePair:update(dt)
    if self.x > -PIPE_WIDTH then
        self.x = self.x - PIPE_SCROLL * dt
        self.pipes['lower'].x = self.X
        self.pipes['upper'].x = self.x
    else
        self.remove = true
    end
end

If anything is unclear or I have left out some vital information I am more than glad to give more information (I am new to Stack Overflow so I am not really sure how everything here works).

(I am using love2d version 11.3 in vscode)

Edit: I pinpointed the error to how I update the self.x in the Pipe class from the PipePair class' update function. Somehow this altering of self.x seems to make it nil.



Solution 1:[1]

I just figured it out!

function PipePair:update(dt)
    if self.x > -PIPE_WIDTH then
        self.x = self.x - PIPE_SCROLL * dt
        self.pipes['lower'].x = self.X
        self.pipes['upper'].x = self.x
    else
        self.remove = true
    end
end

There is a capital X on self.pipes['lower'].x = self.X. For so long I have been trying to figure it out and it was all due to an X. Wow, I feel so stupid.

Solution 2:[2]

the error is saying that a variable is nil, this might have been caused by a typo. and the problem is being caused because of a capital X in self.X

try:

function PipePair:update(dt)
    if self.x > -PIPE_WIDTH then
        self.x = self.x - PIPE_SCROLL * dt
        self.pipes['lower'].x = self.x -- typo was here
        self.pipes['upper'].x = self.x
    else
        self.remove = true
    end
end

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TheDovah7
Solution 2 freeve4