Why does this code not work?

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
Sosolol261
Party member
Posts: 125
Joined: Wed Nov 26, 2014 6:43 am

Why does this code not work?

Post by Sosolol261 »

Code: Select all

function love.draw()
    function mainBackground()
        love.graphics.setBackgroundColor(50, 50, 75)
        love.graphics.rectangle('fill', 0, 520, 1280, 200)
    end
end
Every time I run this code, I get a blackscreen.. The console doesn't tell me anything and the debugger can't find anything too.
I don't think i did anything wrong.
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: Why does this code not work?

Post by Azhukar »

Code: Select all

function love.draw()
        love.graphics.setBackgroundColor(50, 50, 75)
        love.graphics.rectangle('fill', 0, 520, 1280, 200)
end
This will work.

What your code did previously was declare function mainBackground each frame (each time love.draw was called) and then do nothing with it.
Sosolol261
Party member
Posts: 125
Joined: Wed Nov 26, 2014 6:43 am

Re: Why does this code not work?

Post by Sosolol261 »

ah ok thanks :D
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: Why does this code not work?

Post by davisdude »

Alternatively, you could do

Code: Select all

function mainBackground()
    love.graphics.setBackgroundColor(50, 50, 75)
    love.graphics.rectangle('fill', 0, 520, 1280, 200)
end

function love.draw()
    mainBackground()
end
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
MarkSill
Prole
Posts: 13
Joined: Fri Mar 14, 2014 9:14 am

Re: Why does this code not work?

Post by MarkSill »

Or, if you really, really, want to:

Code: Select all

function love.draw()
    function mainBackground()
        love.graphics.setBackgroundColor(50, 50, 75)
        love.graphics.rectangle('fill', 0, 520, 1280, 200)
    end
    mainBackground()
end
Heyo, I'm MarkSill. I'm a programmer, and I like chips with salsa.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 194 guests