I use luas require every time I navigate to a new file. If I try to require a file that is already required, the file I am on just reload itself.
In this example I want to navigate free between different files.
main.lua:
Code: Select all
function love.load()
end
function JUSTLOADTHEFILE(name)
state = {}--one empty table here instead of one in every file. smart?
local path = require(name)
load()--the load function will run in the file
end
function drawsomething()
love.graphics.setColor( 255, 111, 155, 255 )
love.graphics.rectangle( "fill", 400, 0, 400, 600 )
end
function drawsomethingelse()
love.graphics.setColor( 50, 90, 255, 255 )
love.graphics.rectangle( "fill", 0, 300, 800, 300 )
end
function love.draw()
drawsomething() --half screen pink
end
function love.mousepressed( x, y, button )
if button == "l" then
JUSTLOADTHEFILE("file")
elseif button == "r" then
JUSTLOADTHEFILE("anotherfile")
end
end
Code: Select all
function load()
love.graphics.setBackgroundColor( 255, 255, 0 )
end
function love.draw()
drawsomethingelse() --this work
end
function love.mousepressed( x, y, button )
if button == "l" then
JUSTLOADTHEFILE("anotherfile")
elseif button == "r" then
JUSTLOADTHEFILE("main") --I think this is not going to work because it is the main.lua
end
end
Code: Select all
function load()
love.graphics.setBackgroundColor( 255, 255, 255 )
graything = 150
end
function love.update(dt)
graything = graything + 33*dt
if graything > 600 then
graything = 150
end
end
function love.draw()
love.graphics.setColor( 0, 0, 0, 130 )
love.graphics.rectangle( "fill", 200, graything, 400, 300 )
end --this "graything" is just to prove that this file is loaded again instead of the required file
function love.mousepressed( x, y, button )
if button == "l" then
JUSTLOADTHEFILE("main")--also main.lua does not have a function called just "load"
elseif button == "r" then
JUSTLOADTHEFILE("file")
end
end
As said I have had this problem in over a year and it is providing me from continue with learning löve.
Please help me someone.
and no, I do not know how to upload a .love file. I have tried many times.