[Resolved] Odd behavior with additional buttons

Hi all,

I thought I’d run things through here before bringing it to bug reporting.

I’m just about done with my app’s framework but I wanted to add two extra buttons on my front page, leading to simple background images that will lead back when touched.

Oddly, I get these results, while all the other buttons work fine:

Runtime error
…Users/lionelhoude/Desktop/mitm/fixdmitm/director.lua:116: attempt to call field ‘new’ (a nil value)
stack traceback:
[C]: in function ‘new’
…Users/lionelhoude/Desktop/mitm/fixdmitm/director.lua:116: in function ‘loadScene’
…Users/lionelhoude/Desktop/mitm/fixdmitm/director.lua:394: in function ‘changeScene’
/Users/lionelhoude/Desktop/mitm/fixdmitm/menu.lua:72: in function
?: in function <?:226>

My code is:

[code]
module(…, package.seeall)

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

ego = require “ego”
saveFile = ego.saveFile
loadFile = ego.loadFile

local function switchOut()
director:changeScene (“blue”)
end

local volume= loadFile( “volume.txt” )
if volume==“empty” then volume=1.0
end

audio.setVolume( volume )
_G.pizz= loadFile( “gotcha.txt” )

local background = display.newImage (“bg.png”)
localGroup:insert(background)

backgroundMusic = audio.loadStream(“title.mp3”)
backgroundMusicChannel = audio.play( backgroundMusic, { channel=1, loops=0, fadein=5000 } )

local redbutton = display.newImage (“options.png”)
redbutton.x = 160
redbutton.y = 350
localGroup:insert(redbutton)

local about = display.newImage (“aboutbut.png”)
about.x = 160
about.y = 150
localGroup:insert(about)

local credito = display.newImage (“credits.png”)
credito.x = 160
credito.y = 450
localGroup:insert(credito)

local yellowbutton = display.newImage (“continue.png”)
yellowbutton.x = 160
yellowbutton.y = 400
localGroup:insert(yellowbutton)
yellowbutton.isVisible=false
if _G.pizz==“save” then
yellowbutton.isVisible=true
end

local bluebutton = display.newImage (“start.png”)
bluebutton.x = 160
bluebutton.y = 300
localGroup:insert(bluebutton)

local function pressRed (event)
if event.phase == “ended” then
director:changeScene (“red”)
end
end

local function pressBlue (event)
if event.phase == “ended” then
director:changeScene (“yellow”)
end
end

local function creddy (event)
if event.phase == “ended” then
director:changeScene (“credits”)
end
end

local function pressYellow (event)
if event.phase == “ended” then
saveFile( “gotcha.txt”, “save”)
_G.pizz=“save”
_G.usedo = loadFile( “used.txt” )
_G.mo = tonumber(loadFile( “m.txt” ))
_G.ro = tonumber(loadFile( “r.txt” ))
_G.so = tonumber(loadFile( “s.txt” ))
_G.testero = loadFile( “tester.txt” )
_G.tossPVo=tonumber(loadFile(“tosser.txt”))
_G.modeyo=tonumber(loadFile(“modey.txt”))
_G.justTossedo=tonumber(loadFile(“just.txt”))
_G.thediffo=tonumber(loadFile(“thediff.txt”))
timer.performWithDelay(1000, switchOut, 1)
end
end

redbutton:addEventListener (“touch”, pressRed)
bluebutton:addEventListener (“touch”, pressBlue)
credito:addEventListener (“touch”, creddy)
yellowbutton:addEventListener (“touch”, pressYellow)


return localGroup
end[/code]

Am I exceeding some listener limit? Any help is appreciated. Thank you! [import]uid: 144359 topic_id: 28053 reply_id: 328053[/import]

You did not hit some listener limit. Not sure if there is one, really.

I don’t use Director, but it looks like it is having an issue finding the “new” function in the new scenes you added(which I assume one was credits) If you can’t figure it out from there then I would try the director sub forum as it would more likely get noticed by someone with more intimate knowledge.

Being it’s a director thing a bug report to Corona Labs probably won’t help!

[import]uid: 147305 topic_id: 28053 reply_id: 113417[/import]

Hey, sumosalesman:
You aren’t doing the director thing right as far as I know. I think what you need to do is this:

local M={} -- put this instead of the module thingy  
  
function new()  
local localGroup=display.newGroup()  
  
--put your code here  
  
return localGroup -- return your group for director  
end -- end of 'new' function  
  
M.new=new -- must call new as an M function  
  
return M  

hope this helps!
binc [import]uid: 147322 topic_id: 28053 reply_id: 113497[/import]

Thanks Binc! Unfortunately, I still get this:

Runtime error
…Users/lionelhoude/Desktop/mitm/fixdmitm/director.lua:116: attempt to call field ‘new’ (a nil value)
stack traceback:
[C]: in function ‘new’
…Users/lionelhoude/Desktop/mitm/fixdmitm/director.lua:116: in function ‘loadScene’
…Users/lionelhoude/Desktop/mitm/fixdmitm/director.lua:394: in function ‘changeScene’
/Users/lionelhoude/Desktop/mitm/fixdmitm/menu.lua:70: in function
?: in function <?:226>

I was going to change the other secondary pages to your solution, but I still got the same error message when changing the front page and my new credits page to your solution. The original pages do work with your solution in there, just not the credits and about pages.

What’s really bizarre is that I copied red.lua, which worked, to the credits.lua file, and the director still refuses to access credits.lua. Here is my new code. I looked over everything to see if I named it right, etc.:

local M={}  
  
function new()  
 local localGroup = display.newGroup()  
  
ego = require "ego"  
saveFile = ego.saveFile  
loadFile = ego.loadFile  
  
local function switchOut()  
director:changeScene ("blue")  
end  
  
local volume= loadFile( "volume.txt" )  
if volume=="empty" then volume=1.0  
end  
  
audio.setVolume( volume )  
\_G.pizz= loadFile( "gotcha.txt" )  
  
local background = display.newImage ("bg.png")  
localGroup:insert(background)  
  
backgroundMusic = audio.loadStream("title.mp3")  
backgroundMusicChannel = audio.play( backgroundMusic, { channel=1, loops=0, fadein=5000 } )  
  
local redbutton = display.newImage ("options.png")  
redbutton.x = 160  
redbutton.y = 350  
localGroup:insert(redbutton)  
  
local about = display.newImage ("aboutbut.png")  
about.x = 160  
about.y = 150  
localGroup:insert(about)  
  
local credito = display.newImage ("credits.png")  
credito.x = 160  
credito.y = 450  
localGroup:insert(credito)  
  
local yellowbutton = display.newImage ("continue.png")  
yellowbutton.x = 160  
yellowbutton.y = 400  
localGroup:insert(yellowbutton)  
yellowbutton.isVisible=false  
if \_G.pizz=="save" then  
yellowbutton.isVisible=true  
end  
  
local bluebutton = display.newImage ("start.png")  
bluebutton.x = 160  
bluebutton.y = 300  
localGroup:insert(bluebutton)  
  
local function pressRed (event)  
if event.phase == "ended" then  
director:changeScene ("red")  
end  
end  
  
local function pressBlue (event)  
if event.phase == "ended" then  
director:changeScene ("yellow")  
end  
end  
  
local function creddy (event)  
if event.phase == "ended" then  
director:changeScene("credits")  
end  
end  
  
local function pressYellow (event)  
if event.phase == "ended" then  
saveFile( "gotcha.txt", "save")  
\_G.pizz="save"  
\_G.usedo = loadFile( "used.txt" )  
\_G.mo = tonumber(loadFile( "m.txt" ))  
\_G.ro = tonumber(loadFile( "r.txt" ))  
\_G.so = tonumber(loadFile( "s.txt" ))  
\_G.testero = loadFile( "tester.txt" )  
\_G.tossPVo=tonumber(loadFile("tosser.txt"))  
\_G.modeyo=tonumber(loadFile("modey.txt"))  
\_G.justTossedo=tonumber(loadFile("just.txt"))  
\_G.thediffo=tonumber(loadFile("thediff.txt"))  
timer.performWithDelay(1000, switchOut, 1)  
end  
end  
  
redbutton:addEventListener ("touch", pressRed)  
bluebutton:addEventListener ("touch", pressBlue)  
credito:addEventListener ("touch", creddy)  
yellowbutton:addEventListener ("touch", pressYellow)  
------------------------------------------------------------------------------  
------------------------------------------------------------------------------  
return localGroup -- return your group for director  
end -- end of 'new' function  
   
M.new=new -- must call new as an M function  
   
return M  

I appreciate the work. I think I’ll convert to storyboards.

Lionel [import]uid: 144359 topic_id: 28053 reply_id: 113658[/import]

You can’t name a file “credits.lua” because of corona’s in built “credits” api.

Name it something else and it will work :slight_smile: [import]uid: 84637 topic_id: 28053 reply_id: 113982[/import]

That certainly fixed it. Thanks to everyone for the help. Really looking forward to getting this first app done. :smiley: [import]uid: 144359 topic_id: 28053 reply_id: 114333[/import]