Page 2 of 2

Re: Few newbie questions

Posted: Wed Mar 18, 2009 9:59 am
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

Re: Few newbie questions

Posted: Wed Mar 18, 2009 1:00 pm
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.

Re: Few newbie questions

Posted: Wed Mar 18, 2009 3:18 pm
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.

Re: Few newbie questions

Posted: Thu Mar 19, 2009 6:50 am
by someguy99
OK,i finally got it.Edited my first code.Fell free to use it.