Few newbie questions

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
qubodup
Inner party member
Posts: 775
Joined: Sat Jun 21, 2008 9:21 pm
Location: Berlin, Germany
Contact:

Re: Few newbie questions

Post by qubodup »

someguy99 wrote:I really dont know how ill do that.
I imagine that in pseudocode it would be like

Code: Select all

if variable does not equal nil then draw variable
lg.newImage("cat.png") -- made possible by lg = love.graphics
-- Don't force fullscreen (it frustrates those who want to try your game real quick) -- Develop for 1280x720 (so people can make HD videos)
User avatar
someguy99
Prole
Posts: 16
Joined: Tue Mar 17, 2009 5:34 pm

Re: Few newbie questions

Post by someguy99 »

Hm,i shouldve thought about that..
Still doesnt work>i did what you said:

Code: Select all

function load()
   font = love.graphics.newFont(love.default_font, 12)
   love.graphics.setFont(font)
   message = "Error:Some files are missing.Press Escape to exit."
   
   music = love.audio.newMusic("menu.ogg")
   love.audio.play(music,0)
   
   wallpaper = love.graphics.newImage("menu.png")
   play = love.graphics.newImage("play.png")
   options = love.graphics.newImage("options.png")
   about = love.graphics.newImage("about.png")
   exit = love.graphics.newImage("exit.png")
   play_selected = love.graphics.newImage("play_selected.png")
   options_selected = love.graphics.newImage("options_selected.png")
   about_selected = love.graphics.newImage("about_selected.png")
   exit_selected = love.graphics.newImage("exit_selected.png")
   
end


function draw()
   if love.keyboard.isDown(love.key_escape) then
   love.system.exit( ) 
   end
   
   if love.mouse.isDown(love.mouse_left) and x>60 and x<340 and y>660 and y<740 then 
   love.system.exit( ) 
   end
   
   if wallpaper ~= nil then
   love.graphics.draw(wallpaper,512,384)
   end
   
   x = love.mouse.getX( )
   y = love.mouse.getY( ) 
   
   if play ~= nil and play_selected ~= nil and x>60 and x<340 and y>360 and y<440 then
   love.graphics.draw(play_selected,200,400)
   else
   love.graphics.draw(play,200,400)
   end
   
   if options ~= nil and options_selected ~= nil and x>60 and x<340 and y>460 and y<540 then
   love.graphics.draw(options_selected,200,500)
   else
   love.graphics.draw(options,200,500)
   end

   if about ~= nil and about_selected ~= nil and x>60 and x<340 and y>560 and y<640 then
   love.graphics.draw(about_selected,200,600)
   else
   love.graphics.draw(about,200,600)
   end

   if exit ~= nil and exit_selected ~= nil and x>60 and x<340 and y>660 and y<740 then
   love.graphics.draw(exit_selected,200,700)
   else
   love.graphics.draw(exit,200,700)
   end
   
   if love.mouse.isDown(love.mouse_left) and x>60 and x<340 and y>360 and y<440 then
   love.mouse.setVisible(false)
   wallpaper = nil
   play = nil
   options = nil
   about = nil
   exit = nil
   end

end
This should check if the variables arent equal to nil before doing anything.But it gives the same error.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Few newbie questions

Post by bartbes »

Probably because of the code you use for 'selected' images. Example of what you do:

Code: Select all

something = love.graphics.newImage("something")
something_select = love.graphics.newImage("something_selected")

function draw()
    if something and something_select then
        love.graphics.draw(something_select)
    else
        love.graphics.draw(something)
    end
end
(it's not complete, I didn't use coordinates, or the whole check you do, but this is just an example)
(NOTE: if <variable> does exactly the same as if <variable> ~= nil, as nil is parsed as the boolean value false in an if statement)

Now.. let's see when we set something to nil:

Code: Select all

something = nil
something_select = love.graphics.newImage("something_selected")

function draw()
    if something and something_select then  --prevents this from happening, something == nil
        love.graphics.draw(something_select)
    else --so what do we do when something == nil? we try and draw it?!
        love.graphics.draw(something)
    end
end
Hope that helps.
User avatar
someguy99
Prole
Posts: 16
Joined: Tue Mar 17, 2009 5:34 pm

Re: Few newbie questions

Post by someguy99 »

OK,i finally got it.Edited my first code.Fell free to use it.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 2 guests