[Resolved] menus in the menu.lua

Can anybody suggest a way to implement a simple menu
.i.e. PLAY /CREDITS/ HOWTO etc in the main.lua file?

Basically not using director/storyboard etc.

I want something that will halt the gameplay before it starts, cycle through the credits/howto etc then when ready click to start the game.

I had a look at an excellent example in the space shooter code but couldnt get it to work properly, it would cycle through the credits etc but the game would be playing in the background.

What would be nice is a methodology for all us newbies which would help us on principle game logic and ways to develop the game. There is a lot of conflicting information.
[import]uid: 127675 topic_id: 30330 reply_id: 330330[/import]

There isn’t really a simple way to do this without using Director or Storyboard - you’d have to manually hide images yourself. With the lesser option you’d only have to pause timers etc.

Generally people who don’t want to use Director or alternatives end up, eventually, writing their own alternatives simply to make things more manageable.

Have you gotten any code written so far as a start on this? If you do and have a specific issue am happy to try and advise. [import]uid: 52491 topic_id: 30330 reply_id: 121607[/import]

There isn’t really a simple way to do this without using Director or Storyboard - you’d have to manually hide images yourself. With the lesser option you’d only have to pause timers etc.

Generally people who don’t want to use Director or alternatives end up, eventually, writing their own alternatives simply to make things more manageable.

Have you gotten any code written so far as a start on this? If you do and have a specific issue am happy to try and advise. [import]uid: 52491 topic_id: 30330 reply_id: 121607[/import]

@peach pellen

I’ve had a hard time with programing a main menu with stages with director. All I got was having the main menu go to one option, then going back and picking another page, as oppose to having main menu to choose a level then playing that level… Thought about using a main.lua without using director, and can’t get storyboard to work for that purpose. [import]uid: 128294 topic_id: 30330 reply_id: 122768[/import]

Menu.lua would go to something like levels.lua which would have 10 (for example) buttons - each one would go to a level, eg, level1.lua, level2.lua, etc.

Which part of that specifically is getting you stuck? Would like to help but can’t provide a ton of code, so let me know and will do my best to assist you :slight_smile: [import]uid: 52491 topic_id: 30330 reply_id: 122955[/import]

@peach pellen

I was able to get the level button image & back to show up. However when I clicked both, they don’t do anything.

[import]uid: 128294 topic_id: 30330 reply_id: 122971[/import]

Are you getting an error in terminal? [import]uid: 52491 topic_id: 30330 reply_id: 123045[/import]

@peach pellen

Yes.

[text]
Runtime error
assertion failed!
stack traceback:
[C]: ?
[C]: in function ‘assert’
?: in function ‘getOrCreateTable’
?: in function ‘addEventListener’
?: in function ‘addEventListener’
buttonfolder/level1.lua:21: in function ‘new’
buttonfolder/director.lua:116: in function ‘loadScene’
buttonfolder/director.lua:394: in function ‘changeScene’
buttonfolder/levels.lua:24: in function
/buttonfolder/levels.lua:22>
[/text]

[import]uid: 128294 topic_id: 30330 reply_id: 123083[/import]

@peach pellen

I’ve had a hard time with programing a main menu with stages with director. All I got was having the main menu go to one option, then going back and picking another page, as oppose to having main menu to choose a level then playing that level… Thought about using a main.lua without using director, and can’t get storyboard to work for that purpose. [import]uid: 128294 topic_id: 30330 reply_id: 122768[/import]

If you post code I may be able to assist depending on how bulky it is- this is a Director error so would normally go in Director sub forum but if your code is fairly clean I don’t mind skimming it - my guess is it’s in the first or last few lines of levels.lua or level1.lua based on the above error. [import]uid: 52491 topic_id: 30330 reply_id: 123336[/import]

@peach pellen

Does this code look clean? Thought it wouldn’t look too messy.
levels.lua

[lua]module(…, package.seeall)

function new()
local localGroup = display.newGroup()

local background = display.newImage (“mainbackground.jpg”)
localGroup:insert(background)

local level1btn = display.newImage (“level1btn.png”)
level1btn.x = 160
level1btn.y = 200
localGroup:insert(level1btn)

local menubutton = display.newImage (“backbutton.png”)
menubutton.x = 160
menubutton.y = 350
localGroup:insert(menubutton)
local function pressLevel1 (event)
if event.phase == “ended” then
director:changeScene (“level1”)
end
end

level1btn:addEventListener (“touch”, pressLevel1)
local function pressMenubutton (event)
if event.phase == “ended” then
director:changeScene (“menu”)
end
end

menubutton:addEventListener (“touch”, pressMenu)

return localGroup
end[/lua]

and for level1

[lua]module(…, package.seeall)

function new()
local localGroup = display.newGroup()

local background = display.newImage (“mainbackground.jpg”)
localGroup:insert(background)

local level1btn = display.newImage (“level1btn.png”)
level1btn.x = 160
level1btn.y = 200
localGroup:insert(level1btn)

local menubutton = display.newImage (“backbutton.png”)
menubutton.x = 160
menubutton.y = 350
localGroup:insert(menubutton)
local function pressLevel1 (event)
if event.phase == “ended” then
director:changeScene (“level1”)
end
end

level1btn:addEventListener (“touch”, pressLevel1)
local function pressMenubutton (event)
if event.phase == “ended” then
director:changeScene (“menu”)
end
end

menubutton:addEventListener (“touch”, pressMenu)

return localGroup
end[/lua]

Thought I’d just stick with 1 button.
[import]uid: 128294 topic_id: 30330 reply_id: 123339[/import]

That actually looks OK at a glance - nothing stands out as being an issue.

If you are happy to upload this as a zip, or provide plug and play, then I’d be happy to try and make a little time tomorrow to see if I can help you isolate the problem. [import]uid: 52491 topic_id: 30330 reply_id: 123363[/import]

@peach pellen how do you feel about email? [import]uid: 128294 topic_id: 30330 reply_id: 123370[/import]

Menu.lua would go to something like levels.lua which would have 10 (for example) buttons - each one would go to a level, eg, level1.lua, level2.lua, etc.

Which part of that specifically is getting you stuck? Would like to help but can’t provide a ton of code, so let me know and will do my best to assist you :slight_smile: [import]uid: 52491 topic_id: 30330 reply_id: 122955[/import]

@peach pellen

I was able to get the level button image & back to show up. However when I clicked both, they don’t do anything.

[import]uid: 128294 topic_id: 30330 reply_id: 122971[/import]

If you want to email me just your project file (or a cut down version etc) I am happy to take a look and reply here in the thread but wont be able to go back and forth via email - OK?

If that suits - peach[at]coronalabs :slight_smile: [import]uid: 52491 topic_id: 30330 reply_id: 123488[/import]

@peach pellen

Then I will email you the files. [import]uid: 128294 topic_id: 30330 reply_id: 123494[/import]

Are you getting an error in terminal? [import]uid: 52491 topic_id: 30330 reply_id: 123045[/import]

@peach pellen

Yes.

[text]
Runtime error
assertion failed!
stack traceback:
[C]: ?
[C]: in function ‘assert’
?: in function ‘getOrCreateTable’
?: in function ‘addEventListener’
?: in function ‘addEventListener’
buttonfolder/level1.lua:21: in function ‘new’
buttonfolder/director.lua:116: in function ‘loadScene’
buttonfolder/director.lua:394: in function ‘changeScene’
buttonfolder/levels.lua:24: in function
/buttonfolder/levels.lua:22>
[/text]

[import]uid: 128294 topic_id: 30330 reply_id: 123083[/import]

levels.lua line 37;
[lua]menubutton:addEventListener (“touch”, pressMenu)[/lua]
Should be;
[lua]menubutton:addEventListener (“touch”, pressMenubutton)[/lua]

level1.lua line 16;
[lua]director:changeScene (“levelsn”)[/lua]
Should be;
[lua]director:changeScene (“levels”)[/lua]

level1.lua line 20;
[lua]backbutton:addEventListener (“touch”, pressBack)[/lua]
Should be;
[lua]backbutton:addEventListener (“touch”, pressBackbutton)[/lua]

That will fix it.

Peach :slight_smile: [import]uid: 52491 topic_id: 30330 reply_id: 123640[/import]