Hey everyone
Just wondered if it’s possible to create a menu on main.lua and then create the game on a separate LUA file (gameplay.lua)?
I know you can load certain elements from different LUA file, but can I just create the full gameplay on ‘gameplay.lua’ and then create a function so that when you press the start button, it just does whatever is on gameplay.lua?
Thanks a lot
Ace [import]uid: 9899 topic_id: 2989 reply_id: 302989[/import]
Yes, place your gameplay.lua code inside a function new() and then call it: gameplay.new() from main whenever you want. Be sure that the new() function is declared as global (without the local statement). Of course you need to make your gameplay.lua a module, to be visible from other files, so place this in first line:
module(…, package.seeall)
Also, if you have many scenes look in the code exchange section (community tab in site) for the “Director” class.
[import]uid: 7356 topic_id: 2989 reply_id: 8618[/import]
Hey,
Thanks for the reply.
Would this work if I had this in main.lua:
function start:tap ( event )
gameplay.new()
end
start:addEventListener( “tap”, start )
And this in gameplay.lua:
module(…, package.seeall)
function new( ALL MY GAMEPLAY CONTENT HERE )
Or would it be more like:
module(…, package.seeall)
function new()
ALL MY GAMEPLAY CONTENT HERE
end
Or something completely different?
Excuse my newness to Corona and programming
Thanks
Ace
[import]uid: 9899 topic_id: 2989 reply_id: 8624[/import]
The second approach is the right one
module(…, package.seeall)
function new()
ALL MY GAMEPLAY CONTENT HERE
end
However, I would propose to take a look of a mini tutorial I wrote for Lua or read the official Documentation of Ansca. You have to understand the scope concepts to proceed without problems. [import]uid: 7356 topic_id: 2989 reply_id: 8686[/import]
Brilliant, I have it working now.
I’ve been reading loads of things and dissecting the sample projects and watching videos. I feel like I’m learning pretty quickly but I’ve been spending a good 9-11 hours a day on it lol
Thanks a lot, works great
Ace [import]uid: 9899 topic_id: 2989 reply_id: 8690[/import]