Hello im new to love and having some issues with nil value error

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
invisableevil
Prole
Posts: 3
Joined: Wed Jan 20, 2016 10:25 pm

Hello im new to love and having some issues with nil value error

Post by invisableevil »

im trying to fallow this tut and everything is written the same but for some reason his will work in the video and mine ends up with nil value errors left and right

this is the code i am working with

Code: Select all

local Renderer = require "tools/renderer"

renderer = Renderer:create()

function createBox(x,y)
    local b ={}
    
    b.x = x or 0
    b.y = y or 0
    
    function b:load()
        renderer:addRenderer(self,1)
    end
    
    function b:draw()
        love.graphics.setColor(math.random(0,255),math.random(0,255),math.random(0,255))
        love.graphics.rectangle("fill",self.x,self.y,64,64)
    end
    
    return b
end

function love.load()
    rl = createBox(64,64)
    r2 = createBox(96,96)
    
    r1:load()
    r2:load()
end

function love.update(dt)

end

function love.draw()
    renderer:draw()
end
the error seems to be with the r1:load
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Hello im new to love and having some issues with nil value error

Post by zorg »

"Help us help you", post a .love file and/or post the complete error message you're getting; currently i can only say that the error might be in the renderer's lua file.

Then again, i just spotted a potential error. Okay, so a long shot, but either one or the other might be the right solution:

Code: Select all

function b:load()
        renderer.addRenderer(self,1)
    end
or

Code: Select all

function b:load()
        renderer:addRenderer(1)
    end
The difference is that the first passes b as the self parameter, while the other passes renderer as self.
Colon syntax can be misleading when defining functions; they are less so when calling them.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
invisableevil
Prole
Posts: 3
Joined: Wed Jan 20, 2016 10:25 pm

Re: Hello im new to love and having some issues with nil value error

Post by invisableevil »

"Help us help you", post a .love file and/or post the complete error message you're getting; currently i can only say that the error might be in the renderer's lua file.
this is the error

Code: Select all

error

main.lua:27: attempt to index global 'r1' (a nil value)

traceback

main.lua:27: in function 'load'
[C]: infunction 'xpcall'
i dont understand why its doing this
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: Hello im new to love and having some issues with nil value error

Post by arampl »

A typo? You use rl then r1.
invisableevil
Prole
Posts: 3
Joined: Wed Jan 20, 2016 10:25 pm

Re: Hello im new to love and having some issues with nil value error

Post by invisableevil »

arampl wrote:A typo? You use rl then r1.
ignore my last reply u were very right thank you they just look the same in visual studio
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Hello im new to love and having some issues with nil value error

Post by Nixola »

I only approved this message (not the one you say to ignore), but I mistakenly flagged it as "advertising a product" ^^'
Sorry about that and don't worry, I don't think there will be consequences for that.
Anyway, bartbes, is this a bug? He had two posts already, yet I had to approve his messages
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Post Reply

Who is online

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