bad argument #1 to 'draw' (Drawable expected, got nil)

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
JsdLedezma
Prole
Posts: 1
Joined: Tue Oct 06, 2020 12:39 pm

bad argument #1 to 'draw' (Drawable expected, got nil)

Post by JsdLedezma »

Newbie with Löve here, hi.
I'm trying to display an arrow sprite from a class with this code.

Code: Select all

Arrow = Class{}

function Arrow:init(x, y, r)

    self.image = love.graphics.newImage('arrowpic.png')
    
    self.width = self.image:getWidth()
    self.height = self.image:getHeight()

    self.x = x
    self.y = y

    self.ox = self.width / 2
    self.oy = self.height / 2

    self.rotation = math.deg(0)

end

function Arrow:update(dt)
    
    if love.keyboard.wasPressed('space') then
        self.rotation = math.deg(90)
    end

    if love.keyboard.wasPressed('up') then
        if self.rotation == math.deg(0) then
            self.y = self.y - 49
        elseif self.rotation == math.deg(90) then
            self.x = self.x + 49
        elseif self.rotation == math.deg(180) then
            self.y = self.y + 49
        elseif self.rotation == math.deg(270) then
            self.x = self.x - 49
        end
    end
end

function Arrow:render()

    love.graphics.draw(self.image, self.x, self.y, self.rotation, 0, 0, self.ox, self.oy)
   
end
When I run this, it throws this error;

Code: Select all

Error

Arrow.lua:41: bad argument #1 to 'draw' (Drawable expected, got nil)


Traceback

[C]: in function 'draw'
Arrow.lua:41: in function 'render'
main.lua:140: in function 'draw'
[C]: in function 'xpcall'
I tried to look for information about it in the forums but all I got was even more confused, so I come here to ask, please could you explain to me how what I'm trying to do is supposed to be done?

Nowadays I attach the .love file of all what I have of the project in case the error is in the main.lua
Attachments
ArrowAndColorTilesThing.love
(90.87 KiB) Downloaded 141 times
User avatar
CogentInvalid
Prole
Posts: 27
Joined: Sat Dec 14, 2013 12:15 am

Re: bad argument #1 to 'draw' (Drawable expected, got nil)

Post by CogentInvalid »

The error is in main.lua; you're calling Arrow:render() instead of arrow:render().
Post Reply

Who is online

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