How do you go about loading multiple scenes?

How would you go about making menus? I don’t quite understand :confused: I want to have a main menu in main.lua and have my levels in other files (level1.lua,level2.lau,etc) I’ve tried multiple things (like loading like a module) without any success :confused:

Any idea how to go about doing this? [import]uid: 9033 topic_id: 2042 reply_id: 302042[/import]

Excuse my first sentence, not going about making menus… well it’d be used for menus, but more for multiple levels in games. [import]uid: 9033 topic_id: 2042 reply_id: 5981[/import]

Describe “without success” [import]uid: 5712 topic_id: 2042 reply_id: 5983[/import]

Well I wasn’t sure how to properly control removing/adding scenes, if you know how to do it feel free to show me some code :wink:

I just couldn’t figure out for the life of me how to create the entire scene in a separate file and have the adding/removing interact with the main.lua file (I’m assuming that’s how it’s done?)… I’m really not sure, I’m really new the the whole lua thing and I’m probably just overlooking a simple function. [import]uid: 9033 topic_id: 2042 reply_id: 5985[/import]

I think it is better if I don’t write your code for you :slight_smile:

Anyway, it is all a question of design. If you want to use modules I recomment looking into some modules that are already available for Corona. You will see that they are kinda similar to CLASSES from other languages. Also study LUA in the various resources on the net. That will help you on this topic.

But modules are not needed, you can use them but you don’t have to.

And the term SCENE is relative. What do you define as a scene? A game level? In my game that I am working on I have several “layers”. Background, Main menu, help page, options, scorelist! Each of them is its own group. And so I just need to make this group visible when I need it to be. To interact with each group, I use the finite state machine approach, so depending on which state my game is in, I call different functions. [import]uid: 5712 topic_id: 2042 reply_id: 6001[/import]

Oh, I understand lua a decent amount… I just wasn’t sure if there was built in methods in corona to load a different file… I’m all about clean coding, and I think the cleanest approach would be if you were able to code menu.lua and level1.lua and just enter a code like: display.loadSceneFromFile(“level1”) and it would completely remove all the current objects from the memory and load the file level1.
This isn’t possible? [import]uid: 9033 topic_id: 2042 reply_id: 6002[/import]

There is no buildin functionality in Corona for supporting “Scenes” but you can create this yourself and perfectly within a module if you want. [import]uid: 5712 topic_id: 2042 reply_id: 6006[/import]

@eMpire

You can create a module like this:

-- level1.lua  
  
module(..., package.seeall)  
  
local load = function()  
 -- insert some loading code here  
end  

[code]
– main.lua

– require the module
local level1 = require(“level1”)

– load level 1
level1.load()

[/code] [import]uid: 8194 topic_id: 2042 reply_id: 6032[/import]