Page 1 of 1

pls help

Posted: Thu Jan 23, 2025 5:48 pm
by Vandal
Hello! I'm new to game development and to love2d, and I have a problem that I don't know how to solve.
I'm trying to manage different scenes in my game by just loading a file that has all the functions that go into the love.load, love.update and love.draw, and then putting an if statement in each of those that will call upon the respective function, but it's trowing this error to me:
Error

main.lua:23: attempt to call global 'mainMenuLoad' (a nil value)


Traceback

[love "callbacks.lua"]:228: in function 'handler'
main.lua:23: in function 'load'
[love "callbacks.lua"]:136: in function <[love "callbacks.lua"]:135>
[C]: in function 'xpcall'
[C]: in function 'xpcall'

I have not being able to solve this so I'm asking for help, I'll be adding the main.lua file and the main_Menu_Scene.lua file so you can see the code. Thanks in advance, have a nice day!!! :)

Re: pls help

Posted: Thu Jan 23, 2025 6:58 pm
by ivan
"mainMenuLoad" is a local function and since your function is not global it cannot be accessed outside of your "main_menu_scene.lua" file.
You need to learn how to write Lua modules.
Also, try to use more descriptive topic titles in the future.

Re: pls help

Posted: Thu Jan 23, 2025 6:59 pm
by dusoft
Instead of

Code: Select all

local mainMenuScene = love.filesystem.load ('main_Menu_Scene')
you need to require your file.
https://www.lua.org/pil/8.1.html

Re: pls help

Posted: Thu Jan 23, 2025 8:58 pm
by Vandal
ivan wrote: Thu Jan 23, 2025 6:58 pm "mainMenuLoad" is a local function and since your function is not global it cannot be accessed outside of your "main_menu_scene.lua" file.
You need to learn how to write Lua modules.
Also, try to use more descriptive topic titles in the future.
Thank you!! I will sit and learn about lua modules later, but this helped!

Re: pls help

Posted: Thu Jan 23, 2025 9:00 pm
by Vandal
dusoft wrote: Thu Jan 23, 2025 6:59 pm Instead of

Code: Select all

local mainMenuScene = love.filesystem.load ('main_Menu_Scene')
you need to require your file.
https://www.lua.org/pil/8.1.html
Between this reply and the previous one I fixed the problem, thank you so much!!