pls help

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
Vandal
Prole
Posts: 3
Joined: Thu Jan 23, 2025 5:35 pm

pls help

Post 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!!! :)
Attachments
main_Menu_Scene.lua
(5.72 KiB) Downloaded 12 times
main.lua
(798 Bytes) Downloaded 8 times
User avatar
ivan
Party member
Posts: 1922
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: pls help

Post 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.
User avatar
dusoft
Party member
Posts: 701
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: pls help

Post 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
Vandal
Prole
Posts: 3
Joined: Thu Jan 23, 2025 5:35 pm

Re: pls help

Post 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!
Vandal
Prole
Posts: 3
Joined: Thu Jan 23, 2025 5:35 pm

Re: pls help

Post 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!!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 4 guests