changing lua file as main thread

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
User avatar
elbrunzy
Prole
Posts: 13
Joined: Sun May 03, 2015 5:29 am

changing lua file as main thread

Post by elbrunzy »

Hi

I realize setting up the structure of my game project menu/animation/game mechanism as three independent love2d executable and relying on os.execute to call each program have some drawback and trying to solve them I read something about running all the .lua file inside a single love thread.

Reading about thread system of love2d I wonder if I could have the main thread reload itself using a new .lua file. The main menu program would be called main.lua and would eventually ask the main love thread to restart itself using a new anim.lua or game.lua file.

Maybe another method could be to have all three thread running together but having them paused and started with the window passed to each of them. But I dont need any inter process since all logic in each program is coded to exchange data using the game save file that is in the same love.filesystem via a shared identity, it is read at startup of each program. Maybe it would be easier to just restart using a different .lua file for main thread.

Thank you
User avatar
dusoft
Party member
Posts: 676
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: changing lua file as main thread

Post by dusoft »

I think you are overcomplicating here. What you are after are gamestates.

Check these libs (search for gamestate):
https://github.com/love2d-community/awesome-love2d

See e.g. how hump manages game states:
https://hump.readthedocs.io/en/latest/gamestate.html

Yes, you have separate files, but no filesystem calls are necessary, you just basically redeclare used functions.

Edit: Instead of love.filesystem and using external library, you can use require function: https://www.lua.org/pil/8.1.html
Just redeclare love.update, love.draw etc. functions in each file and you are all set, call require when ready to switch the game state.

That's also how my primitive state switcher used to work (do not use it, ugly, outdated etc.!): https://ambience.sk/love2d-a-state-switcher-class-lua/
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 8 guests