Page 1 of 1

delete post

Posted: Wed Feb 20, 2013 7:22 pm
by jajasuperman
delete post

Re: [Problem] How I use dofile?

Posted: Wed Feb 20, 2013 8:11 pm
by Nixola
You should use require (don't write .lua, "require('level1')) or love.filesystem.load (you'll have to call what it returns: level1 = lf.load('level1.lua'); level1()) instead

delete post

Posted: Wed Feb 20, 2013 9:40 pm
by jajasuperman
delete post

Re: [Problem] How I use dofile?

Posted: Wed Feb 20, 2013 9:47 pm
by Nixola
The problem is that player is a variable that doesn't exist yet in line 33 of level1.lua, according to the message; if you posted some other code we'd be able to tell you what's the problem exactly

delete post

Posted: Wed Feb 20, 2013 10:09 pm
by jajasuperman
delete post

Re: [Problem] How I use dofile?

Posted: Wed Feb 20, 2013 10:13 pm
by Nixola
You define the callbacks twice, you should never do that; when you load level1.lua the callbacks inside it overwrite the ones defined inside main.lua, and level1.lua's love.load doesn't ever get called

Re: [Problem] How I use dofile?

Posted: Thu Feb 21, 2013 2:31 am
by Qcode
I know that this isn't the point of the post, but I noticed your love.draw function was slightly redundant.
It is currently this:

Code: Select all

function love.draw()
        if menu == 1 then
                love.graphics.setColor(255, 0, 0)
                love.graphics.print("Jugar", 100, 100, 0, 2, 2)
               
                love.graphics.setColor(0, 0, 255)
                love.graphics.print("Opciones", 100, 200, 0, 2, 2)
               
                love.graphics.setColor(0, 0, 255)
                love.graphics.print("Salir", 100, 300, 0, 2, 2)
        end
       
        if menu == 2 then
                love.graphics.setColor(0, 0, 255)
                love.graphics.print("Jugar", 100, 100, 0, 2, 2)
               
                love.graphics.setColor(255, 0, 0)
                love.graphics.print("Opciones", 100, 200, 0, 2, 2)
               
                love.graphics.setColor(0, 0, 255)
                love.graphics.print("Salir", 100, 300, 0, 2, 2)
        end
       
        if menu == 3 then
                love.graphics.setColor(0, 0, 255)
                love.graphics.print("Jugar", 100, 100, 0, 2, 2)
               
                love.graphics.setColor(0, 0, 255)
                love.graphics.print("Opciones", 100, 200, 0, 2, 2)
               
                love.graphics.setColor(255, 0, 0)
                love.graphics.print("Salir", 100, 300, 0, 2, 2)
        end
end
It can be simplified down to this

Code: Select all

function love.draw()
                love.graphics.setColor(0, 0, 255)
                if menu == 1 then
                        love.graphics.setColor(255, 0, 0)
                end
                love.graphics.print("Jugar", 100, 100, 0, 2, 2)
               
                love.graphics.setColor(0, 0, 255)
                if menu == 2 then
                        love.graphics.setColor(255, 0, 0)
                end
                love.graphics.print("Opciones", 100, 200, 0, 2, 2)
               
                love.graphics.setColor(0, 0, 255)
                if menu == 3 then
                        love.graphics.setColor(255, 0, 0)
                end
                love.graphics.print("Salir", 100, 300, 0, 2, 2)
        end
end
Just my two cents though. Have fun löving!

Re: [Problem] How I use dofile?

Posted: Thu Feb 21, 2013 1:09 pm
by vitaminx
I was struggling with that too, finally require("filename") works for me, but without the lua extension, e.g.: require("level1").

delete post

Posted: Thu Feb 21, 2013 2:32 pm
by jajasuperman
delete post