delete post

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
jajasuperman
Prole
Posts: 16
Joined: Wed Feb 20, 2013 7:16 pm

delete post

Post by jajasuperman »

delete post
Last edited by jajasuperman on Mon Feb 05, 2018 12:53 pm, edited 3 times in total.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: [Problem] How I use dofile?

Post 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
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
jajasuperman
Prole
Posts: 16
Joined: Wed Feb 20, 2013 7:16 pm

delete post

Post by jajasuperman »

delete post
Last edited by jajasuperman on Mon Feb 05, 2018 12:53 pm, edited 1 time in total.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: [Problem] How I use dofile?

Post 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
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
jajasuperman
Prole
Posts: 16
Joined: Wed Feb 20, 2013 7:16 pm

delete post

Post by jajasuperman »

delete post
Last edited by jajasuperman on Mon Feb 05, 2018 12:53 pm, edited 1 time in total.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: [Problem] How I use dofile?

Post 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
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Qcode
Party member
Posts: 170
Joined: Tue Jan 10, 2012 1:35 am

Re: [Problem] How I use dofile?

Post 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!
User avatar
vitaminx
Citizen
Posts: 95
Joined: Fri Oct 19, 2012 7:16 am
Location: international
Contact:

Re: [Problem] How I use dofile?

Post by vitaminx »

I was struggling with that too, finally require("filename") works for me, but without the lua extension, e.g.: require("level1").
jajasuperman
Prole
Posts: 16
Joined: Wed Feb 20, 2013 7:16 pm

delete post

Post by jajasuperman »

delete post
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest