Error when trying to insert text into scene

I am trying to create buttons for a menu with text instruction above them. The issue I am having is that when I insert the text into the scene it doesn’t work. It works when I take all the text stuff out but I can’t work out what I am doing wrong with the text. Any help would be appreciated.

Code - 

local composer = require( "composer" ) local scene = composer.newScene() local widget = require("widget") local function gotoX()   composer.gotoScene( "xHvhGame" ) end local function gotoO()   composer.gotoScene( "oHvhGame" ) end local function xHandleButtonEvent(event)     if ("began" == event.phase) then       gotoX()     end return true  end      local function oHandleButtonEvent(event)     if ("began" == event.phase) then       gotoO()     end return true  end --setup the buttons local xButton = widget.newButton{     id = "X", -- id is unique and essential when using event handlers (see addEventListener below)     shape = "roundedRect",     x = x,     y = y,     width = 124,     height = 124,     cornerRadius = 2,     fillColor = {default={ 1, 0.2, 0.5, 0.7 }, over={ 1, 0.2, 0.5, 1 }},     strokeColor = {default={ 0, 0, 0 }, over={ 0.4, 0.1, 0.2 }},     strokeWidth = 4,      onEvent = xHandleButtonEvent,     label = "X" } local oButton = widget.newButton{     id = "O", -- id is again unique     shape = "roundedRect",     x = x,     y = y,     width = 124,     height = 124,     cornerRadius = 2,     fillColor = {default={ 1, 0.2, 0.5, 0.7 }, over={ 1, 0.2, 0.5, 1 }},     strokeColor = {default={ 0, 0, 0 }, over={ 0.4, 0.1, 0.2 }},     strokeWidth = 4 ,     onEvent = oHandleButtonEvent,     label = "O" } local menuText = display.newText("Choose icon for Player One", 200, 100, "Arial", 20) xButton.x = 100  xButton.y = 200 oButton.x = 250 oButton.y = 200 function scene:create( event )  local sceneGroup = self.view  sceneGroup:insert(menuText)  sceneGroup:insert(xButton)  sceneGroup:insert(oButton) end -- show() function scene:show( event )     local sceneGroup = self.view     local phase = event.phase     if ( phase == "will" ) then         -- Code here runs when the scene is still off screen (but is about to come on screen)     elseif ( phase == "did" ) then         -- Code here runs when the scene is entirely on screen     end end -- hide() function scene:hide( event )     local sceneGroup = self.view     local phase = event.phase     if ( phase == "will" ) then         -- Code here runs when the scene is on screen (but is about to go off screen)     elseif ( phase == "did" ) then         -- Code here runs immediately after the scene goes entirely off screen     end end -- destroy() function scene:destroy( event )     local sceneGroup = self.view end -- ----------------------------------------------------------------------------------- -- Scene event function listeners -- ----------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ----------------------------------------------------------------------------------- return scene

I would do:

function scene:create( event ) local sceneGroup = self.view --setup the buttons local xButton = widget.newButton{ id = "X", -- id is unique and essential when using event handlers (see addEventListener below) shape = "roundedRect", x = x, y = y, width = 124, height = 124, cornerRadius = 2, fillColor = {default={ 1, 0.2, 0.5, 0.7 }, over={ 1, 0.2, 0.5, 1 }}, strokeColor = {default={ 0, 0, 0 }, over={ 0.4, 0.1, 0.2 }}, strokeWidth = 4, onEvent = xHandleButtonEvent, label = "X" } local oButton = widget.newButton{ id = "O", -- id is again unique shape = "roundedRect", x = x, y = y, width = 124, height = 124, cornerRadius = 2, fillColor = {default={ 1, 0.2, 0.5, 0.7 }, over={ 1, 0.2, 0.5, 1 }}, strokeColor = {default={ 0, 0, 0 }, over={ 0.4, 0.1, 0.2 }}, strokeWidth = 4 , onEvent = oHandleButtonEvent, label = "O" } local menuText = display.newText("Choose icon for Player One", 200, 100, "Arial", 20) xButton.x = 100 xButton.y = 200 oButton.x = 250 oButton.y = 200 sceneGroup:insert(menuText) sceneGroup:insert(xButton) sceneGroup:insert(oButton) end

That’s a more proper way to use Composer’s scene management.

As for the text not showing what color is your background? What color is the foreground text supposed to be? You may want to do a:

menuText:setFillColor()

call and explicitly set the text color.

Rob

I would do:

function scene:create( event ) local sceneGroup = self.view --setup the buttons local xButton = widget.newButton{ id = "X", -- id is unique and essential when using event handlers (see addEventListener below) shape = "roundedRect", x = x, y = y, width = 124, height = 124, cornerRadius = 2, fillColor = {default={ 1, 0.2, 0.5, 0.7 }, over={ 1, 0.2, 0.5, 1 }}, strokeColor = {default={ 0, 0, 0 }, over={ 0.4, 0.1, 0.2 }}, strokeWidth = 4, onEvent = xHandleButtonEvent, label = "X" } local oButton = widget.newButton{ id = "O", -- id is again unique shape = "roundedRect", x = x, y = y, width = 124, height = 124, cornerRadius = 2, fillColor = {default={ 1, 0.2, 0.5, 0.7 }, over={ 1, 0.2, 0.5, 1 }}, strokeColor = {default={ 0, 0, 0 }, over={ 0.4, 0.1, 0.2 }}, strokeWidth = 4 , onEvent = oHandleButtonEvent, label = "O" } local menuText = display.newText("Choose icon for Player One", 200, 100, "Arial", 20) xButton.x = 100 xButton.y = 200 oButton.x = 250 oButton.y = 200 sceneGroup:insert(menuText) sceneGroup:insert(xButton) sceneGroup:insert(oButton) end

That’s a more proper way to use Composer’s scene management.

As for the text not showing what color is your background? What color is the foreground text supposed to be? You may want to do a:

menuText:setFillColor()

call and explicitly set the text color.

Rob