Hello, I'm new to Löve2D and LUA in general. My goal is to create a simple menu with a background, so I installed "stateswitcher" (https://love2d.org/wiki/Stateswitcher).
In my "menu.lua" I tried to load this image and draw it, but it won't work:
Error
menu.lua:16: bad argument #1 to 'draw' (Drawable expected, got nil)
Traceback
[C]: in function 'draw'
menu.lua:16: in function 'draw'
[C]: in function 'xpcall'
state=require("lib.state.stateswitcher")
anim = require('lib.anim8.anim8')
function love.load()
bgimg = love.graphics.newImage("img/bg.png")
end
function love.update(dt)
end
function love.draw()
love.graphics.draw(bgimg)
end
If I use the menu.lua code in my "main.lua" without stateswitcher it works like a charm.
I'm guessing that love.load in your menu.lua doesn't run, since it already ran in main.lua and it's only called exactly once.
You can remedy this problem by modifying the state switcher code a little; after the line where it requires target module, you would manually call love.load function.
BurningScript wrote: ↑Wed Oct 02, 2019 7:04 pm
What am I doing wrong?
Hello, welcome to the forums. The problem is that this library is not very well designed; the error comes from the fact that it won't execute love.load events in the code it loads. It also has more problems: it won't clear old events when switching from one state to another, meaning that if you switch from a file that has a certain event, to a file that doesn't, that event will still be active.
My advice is to change to another library with a different design, or implement state switching yourself. If you opt for the pre-made library, one possible recommendation would be Hump. If you opt for the second one, I give some indications here: https://love2d.org/forums/viewtopic.php ... 26#p194226
BurningScript wrote: ↑Wed Oct 02, 2019 7:04 pm
What am I doing wrong?
Hello, welcome to the forums. The problem is that this library is not very well designed; the error comes from the fact that it won't execute love.load events in the code it loads. It also has more problems: it won't clear old events when switching from one state to another, meaning that if you switch from a file that has a certain event, to a file that doesn't, that event will still be active.
My advice is to change to another library with a different design, or implement state switching yourself. If you opt for the pre-made library, one possible recommendation would be Hump. If you opt for the second one, I give some indications here: https://love2d.org/forums/viewtopic.php ... 26#p194226
Thank you very much! I already changed to HUMP and it works without any problem!