Removal of native.newTextField

Hi guys,

Im having a little trouble with removing some native.newTextFields which I am using for players to login to my game. They hold username and password and when I press the login button I will authenticate (not built yet) and on success remove the text fields and go to the main menu.

Currently all other objects on the scene are removed correctly but I just cant get rid of these. I have added them to the scene group. I have found the object:removeSelf(). I think I’m just putting it in the wrong place. Also this doesn’t appear as problem on simulator just on phone.

Edit: this errors with removeselfs in just put in to show you what I was trying.

------userlogin.lua-------

local function handleSummonChampionButtonEvent( event )
    if ( “ended” == event.phase ) then
     SummonChampionUsername:removeSelf()
     SummonChampionUsername = nil
     SummonChampionPassword:removeSelf()
     SummonChampionPassword = nil  
     composer.removeScene( “userlogin”, true )
      composer.gotoScene(“menu”, { effect = “crossFade”, time = 333 })
    end
end

    – SummonChampionButtonEvent

    local SummonChampionButton = widget.newButton({
          id = “loginbutton2”,
    defaultFile = “SummonChampion.png”,
          onRelease = handleSummonChampionButtonEvent
 
    })
    SummonChampionButton.x = display.contentCenterX * 1
    SummonChampionButton.y = display.contentCenterY * 1.4
    sceneGroup:insert( SummonChampionButton )
  
   --SummonChampionUsername
  
   local SummonChampionUsername = native.newTextField(display.contentCenterX*1, display.contentCenterY * 0.8, display.contentWidth /3, display.contentHeight/9)
   SummonChampionUsername:setTextColor( 0, 0, 0 )
   SummonChampionUsername.isEditable = true
   sceneGroup:insert( SummonChampionUsername )
  
   --SummonChampionPassword
  
   local SummonChampionPassword = native.newTextField(display.contentCenterX*1, display.contentCenterY * 1.1, display.contentWidth /3, display.contentHeight/9)
   SummonChampionPassword:setTextColor( 0, 0, 0 )
   SummonChampionPassword.isEditable = true
   sceneGroup:insert( SummonChampionPassword )
  

Hi @davidlewis02,

Is the code that you posted the exact “scope” that’s in your project? Meaning, do you declare the native text fields below the function where you remove them? If so, then Lua will not know what objects you are referring to, and it won’t remove them. If that is the case, then the solution is to just fix the scope, for example upvalue declare the references to the native text fields above the function where you remove them.

Best regards,

Brent

Hi Brent sorry for not posting all the code thought it may have just been a syntax thing. I thought I managed to remove the Textfields as the simulator started to show the error and I managed to remove it. But when on my phone the textFields are still not removed. I also get an error now when going to my forgot password screen > back to login then press summon champion says Im trying to remove textFild with nil value. Been my first week so I may well be structuring things wrong (sorry for wall of text :D):

-------------------------userlogin.lua-------------------------------------------------------------------- local composer = require( "composer" )local scene = composer.newScene()local widget = require( "widget" )local utility = require( "utility" )local ads = require( "ads" )local paramslocal myData = require( "mydata" )    --SummonChampionUsername   local SummonChampionUsername = native.newTextField(display.contentCenterX\*1, display.contentCenterY \* 0.85, display.contentWidth /3, display.contentHeight/9)   SummonChampionUsername.placeholder = "(Email)"   SummonChampionUsername:setTextColor( 0, 0, 0 )   SummonChampionUsername.isEditable = true   --sceneGroup:insert( SummonChampionUsername )     --SummonChampionPassword   local SummonChampionPassword = native.newTextField(display.contentCenterX\*1, display.contentCenterY \* 1.1, display.contentWidth /3, display.contentHeight/9)   SummonChampionPassword.placeholder = "(Password)"   SummonChampionPassword:setTextColor( 0, 0, 0 )   SummonChampionPassword.isEditable = true   --sceneGroup:insert( SummonChampionPassword )  local function handleSummonChampionButtonEvent( event )    if ( "ended" == event.phase ) then      SummonChampionUsername:removeSelf()        SummonChampionPassword:removeSelf()        composer.removeScene( "userlogin", true )        composer.gotoScene("menu", { effect = "crossFade", time = 333 })    endend local function handleCreateChampionScreenButton( event )    if ( "ended" == event.phase ) then     SummonChampionUsername:removeSelf()        SummonChampionPassword:removeSelf()        composer.removeScene( "userlogin", true )        composer.gotoScene("createuser", { effect = "crossFade", time = 333 })    endend local function handleCreateForgotPasswordScreenButton( event )    if ( "ended" == event.phase ) then     SummonChampionUsername:removeSelf()        SummonChampionPassword:removeSelf()        composer.removeScene( "userlogin", true )        composer.gotoScene("ForgotPassword", { effect = "crossFade", time = 333 })    endend local function onRememberMeCheckBox( event )    local switch = event.target    if switch.isOn then        switch.isOn = true    else        switch.isOn = false  endend function scene:create( event )    local sceneGroup = self.view     params = event.params local background = display.newImage( "Background.png", display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight )    sceneGroup:insert( background )     -- SummonChampionButtonEvent    local SummonChampionButton = widget.newButton({          id = "loginbutton2",    defaultFile = "SummonChampion.png",          onRelease = handleSummonChampionButtonEvent     })    SummonChampionButton.x = display.contentCenterX \* 1    SummonChampionButton.y = display.contentCenterY \* 1.4    sceneGroup:insert( SummonChampionButton )     --SummonChampionUsername   local SummonChampionUsername = native.newTextField(display.contentCenterX\*1, display.contentCenterY \* 0.85, display.contentWidth /3, display.contentHeight/9)   SummonChampionUsername.placeholder = "(Email)"   SummonChampionUsername:setTextColor( 0, 0, 0 )   SummonChampionUsername.isEditable = true   sceneGroup:insert( SummonChampionUsername )     --SummonChampionPassword   local SummonChampionPassword = native.newTextField(display.contentCenterX\*1, display.contentCenterY \* 1.1, display.contentWidth /3, display.contentHeight/9)   SummonChampionPassword.placeholder = "(Password)"   SummonChampionPassword:setTextColor( 0, 0, 0 )   SummonChampionPassword.isEditable = true   sceneGroup:insert( SummonChampionPassword )     --ForgotPasswordScreen    local CreateForgotPasswordScreenButton = widget.newButton({        id = "CreateForgotPasswordScreenButton",        defaultFile = "forgotpassword.png",        onRelease = handleCreateForgotPasswordScreenButton    })    CreateForgotPasswordScreenButton.x = display.contentCenterX \* 1.5    CreateForgotPasswordScreenButton.y = display.contentCenterY \* 1.8    sceneGroup:insert( CreateForgotPasswordScreenButton )     --CreateChampionScreen    local CreateChampionScreenButton = widget.newButton({        id = "CreateChampionScreenButton",         defaultFile = "createchampionlogin.png",        onRelease = handleCreateChampionScreenButton    })    CreateChampionScreenButton.x = display.contentCenterX \* 0.5    CreateChampionScreenButton.y = display.contentCenterY \* 1.8    sceneGroup:insert( CreateChampionScreenButton )     --RememberMe     local RememberMe = widget.newButton({          id = "rememberme",    defaultFile = "rememberme.png"     })    RememberMe.x = display.contentCenterX \* 0.95    RememberMe.y = display.contentCenterY \* 1.6    sceneGroup:insert( RememberMe )       --RememberMeCheckBox   local RememberMeCheckBox = widget.newSwitch   {    left = display.contentCenterX \* 1.15,    top = display.contentCenterY \* 1.5,    style = "checkbox",    id = "RememberMeCheckBox",    initialSwitchState = true,    onPress = onRememberMeCheckBox    }    sceneGroup:insert( RememberMeCheckBox )    end  function scene:show( event )    local sceneGroup = self.view    params = event.params    if event.phase == "did" then        endend function scene:hide( event )    local sceneGroup = self.view      if event.phase == "will" then    end end function scene:destroy( event )    local sceneGroup = self.view   end ----------------------------------------------------------------------------------- END OF YOUR IMPLEMENTATION---------------------------------------------------------------------------------scene:addEventListener( "create", scene )scene:addEventListener( "show", scene )scene:addEventListener( "hide", scene )scene:addEventListener( "destroy", scene )return scene ---------------------------ForgotPassword.lua------------------------------------------------------ local composer = require( "composer" )local scene = composer.newScene()local widget = require( "widget" )local utility = require( "utility" )local ads = require( "ads" )local paramslocal myData = require( "mydata" ) local function handleRetrievePasswordButton( event )    if ( "ended" == event.phase ) then        composer.removeScene( "ForgotPassword", true )        composer.gotoScene("userlogin", { effect = "crossFade", time = 333 })    endend local function handleReturntoLoginScreenButton( event )    if ( "ended" == event.phase ) then        composer.removeScene( "ForgotPassword", true )        composer.gotoScene("userlogin", { effect = "crossFade", time = 333 })    endend function scene:create( event )    local sceneGroup = self.view     params = event.params   local background = display.newImage( "Background.png", display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight )    sceneGroup:insert( background )     --ForgotPasswordEmail     local ForgotPasswordEmail = native.newTextField(display.contentCenterX\*1, display.contentCenterY \* 1.2, display.contentWidth /3.5, display.contentHeight/11)   ForgotPasswordEmail:setTextColor( 1, 1, 1 )   ForgotPasswordEmail.isEditable = true   sceneGroup:insert( ForgotPasswordEmail )     -- RetrievePasswordButton    local RetrievePasswordButton = widget.newButton({        id = "RetrievePasswordButton",  defaultFile = "retrievepassword.png",        onRelease = handleRetrievePasswordButton    })    RetrievePasswordButton.x = display.contentCenterX    RetrievePasswordButton.y = display.contentCenterY \*1.4    sceneGroup:insert( RetrievePasswordButton )     -- Return to Login Screen    local ReturntoLoginScreenButton = widget.newButton({        id = "ReturntoLoginScreenButton",        defaultFile ="backtologin.png",        onRelease = handleReturntoLoginScreenButton    })    ReturntoLoginScreenButton.x = display.contentCenterX    ReturntoLoginScreenButton.y = display.contentCenterY \*1.7    sceneGroup:insert( ReturntoLoginScreenButton ) end function scene:show( event )    local sceneGroup = self.view     params = event.params     if event.phase == "did" then    endend function scene:hide( event )    local sceneGroup = self.view       if event.phase == "will" then    end end function scene:destroy( event )    local sceneGroup = self.view   end ----------------------------------------------------------------------------------- END OF YOUR IMPLEMENTATION---------------------------------------------------------------------------------scene:addEventListener( "create", scene )scene:addEventListener( "show", scene )scene:addEventListener( "hide", scene )scene:addEventListener( "destroy", scene )return scene

Please edit your post, highlight your code and click on the <> tag in the edit bar so your code highlights correctly.

Thanks

Rob

Hi Rob edited as requested will make sure I do this from now on.

Thanks

Well that didn’t help.  In fact it made it worse.  In the future, when pasting your code in, use the <>, but perhaps going back and editing an already posted block of code reformatted the code poorly.

Rob

Apologies Rob have adjusted:

-----------userlogin.lua----------------- local composer = require( "composer" ) local scene = composer.newScene() local widget = require( "widget" ) local utility = require( "utility" ) local ads = require( "ads" ) local params local myData = require( "mydata" ) --SummonChampionUsername local SummonChampionUsername = native.newTextField(display.contentCenterX\*1, display.contentCenterY \* 0.85, display.contentWidth /3, display.contentHeight/9) SummonChampionUsername.placeholder = "(Email)" SummonChampionUsername:setTextColor( 0, 0, 0 ) SummonChampionUsername.isEditable = true --sceneGroup:insert( SummonChampionUsername ) --SummonChampionPassword local SummonChampionPassword = native.newTextField(display.contentCenterX\*1, display.contentCenterY \* 1.1, display.contentWidth /3, display.contentHeight/9) SummonChampionPassword.placeholder = "(Password)" SummonChampionPassword:setTextColor( 0, 0, 0 ) SummonChampionPassword.isEditable = true --sceneGroup:insert( SummonChampionPassword ) local function handleSummonChampionButtonEvent( event ) if ( "ended" == event.phase ) then SummonChampionUsername:removeSelf() SummonChampionPassword:removeSelf() composer.removeScene( "userlogin", true ) composer.gotoScene("menu", { effect = "crossFade", time = 333 }) end end local function handleCreateChampionScreenButton( event ) if ( "ended" == event.phase ) then SummonChampionUsername:removeSelf() SummonChampionPassword:removeSelf() composer.removeScene( "userlogin", true ) composer.gotoScene("createuser", { effect = "crossFade", time = 333 }) end end local function handleCreateForgotPasswordScreenButton( event ) if ( "ended" == event.phase ) then SummonChampionUsername:removeSelf() SummonChampionPassword:removeSelf() composer.removeScene( "userlogin", true ) composer.gotoScene("ForgotPassword", { effect = "crossFade", time = 333 }) end end local function onRememberMeCheckBox( event ) local switch = event.target if switch.isOn then switch.isOn = true else switch.isOn = false end end function scene:create( event ) local sceneGroup = self.view params = event.params local background = display.newImage( "Background.png", display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight ) sceneGroup:insert( background ) -- SummonChampionButtonEvent local SummonChampionButton = widget.newButton({ id = "loginbutton2", defaultFile = "SummonChampion.png", onRelease = handleSummonChampionButtonEvent }) SummonChampionButton.x = display.contentCenterX \* 1 SummonChampionButton.y = display.contentCenterY \* 1.4 sceneGroup:insert( SummonChampionButton ) --SummonChampionUsername local SummonChampionUsername = native.newTextField(display.contentCenterX\*1, display.contentCenterY \* 0.85, display.contentWidth /3, display.contentHeight/9) SummonChampionUsername.placeholder = "(Email)" SummonChampionUsername:setTextColor( 0, 0, 0 ) SummonChampionUsername.isEditable = true sceneGroup:insert( SummonChampionUsername ) --SummonChampionPassword local SummonChampionPassword = native.newTextField(display.contentCenterX\*1, display.contentCenterY \* 1.1, display.contentWidth /3, display.contentHeight/9) SummonChampionPassword.placeholder = "(Password)" SummonChampionPassword:setTextColor( 0, 0, 0 ) SummonChampionPassword.isEditable = true sceneGroup:insert( SummonChampionPassword ) --ForgotPasswordScreen local CreateForgotPasswordScreenButton = widget.newButton({ id = "CreateForgotPasswordScreenButton", defaultFile = "forgotpassword.png", onRelease = handleCreateForgotPasswordScreenButton }) CreateForgotPasswordScreenButton.x = display.contentCenterX \* 1.5 CreateForgotPasswordScreenButton.y = display.contentCenterY \* 1.8 sceneGroup:insert( CreateForgotPasswordScreenButton ) --CreateChampionScreen local CreateChampionScreenButton = widget.newButton({ id = "CreateChampionScreenButton", defaultFile = "createchampionlogin.png", onRelease = handleCreateChampionScreenButton }) CreateChampionScreenButton.x = display.contentCenterX \* 0.5 CreateChampionScreenButton.y = display.contentCenterY \* 1.8 sceneGroup:insert( CreateChampionScreenButton ) --RememberMe local RememberMe = widget.newButton({ id = "rememberme", defaultFile = "rememberme.png" }) RememberMe.x = display.contentCenterX \* 0.95 RememberMe.y = display.contentCenterY \* 1.6 sceneGroup:insert( RememberMe ) --RememberMeCheckBox local RememberMeCheckBox = widget.newSwitch { left = display.contentCenterX \* 1.15, top = display.contentCenterY \* 1.5, style = "checkbox", id = "RememberMeCheckBox", initialSwitchState = true, onPress = onRememberMeCheckBox } sceneGroup:insert( RememberMeCheckBox ) end function scene:show( event ) local sceneGroup = self.view params = event.params if event.phase == "did" then end end function scene:hide( event ) local sceneGroup = self.view if event.phase == "will" then end end function scene:destroy( event ) local sceneGroup = self.view end --------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) return scene --------------forgotpassword.lua----------------- local composer = require( "composer" ) local scene = composer.newScene() local widget = require( "widget" ) local utility = require( "utility" ) local ads = require( "ads" ) local params local myData = require( "mydata" ) local function handleRetrievePasswordButton( event ) if ( "ended" == event.phase ) then composer.removeScene( "ForgotPassword", true ) composer.gotoScene("userlogin", { effect = "crossFade", time = 333 }) end end local function handleReturntoLoginScreenButton( event ) if ( "ended" == event.phase ) then composer.removeScene( "ForgotPassword", true ) composer.gotoScene("userlogin", { effect = "crossFade", time = 333 }) end end function scene:create( event ) local sceneGroup = self.view params = event.params local background = display.newImage( "Background.png", display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight ) sceneGroup:insert( background ) --ForgotPasswordEmail local ForgotPasswordEmail = native.newTextField(display.contentCenterX\*1, display.contentCenterY \* 1.2, display.contentWidth /3.5, display.contentHeight/11) ForgotPasswordEmail:setTextColor( 1, 1, 1 ) ForgotPasswordEmail.isEditable = true sceneGroup:insert( ForgotPasswordEmail ) -- RetrievePasswordButton local RetrievePasswordButton = widget.newButton({ id = "RetrievePasswordButton", defaultFile = "retrievepassword.png", onRelease = handleRetrievePasswordButton }) RetrievePasswordButton.x = display.contentCenterX RetrievePasswordButton.y = display.contentCenterY \*1.4 sceneGroup:insert( RetrievePasswordButton ) -- Return to Login Screen local ReturntoLoginScreenButton = widget.newButton({ id = "ReturntoLoginScreenButton", defaultFile ="backtologin.png", onRelease = handleReturntoLoginScreenButton }) ReturntoLoginScreenButton.x = display.contentCenterX ReturntoLoginScreenButton.y = display.contentCenterY \*1.7 sceneGroup:insert( ReturntoLoginScreenButton ) end function scene:show( event ) local sceneGroup = self.view params = event.params if event.phase == "did" then end end function scene:hide( event ) local sceneGroup = self.view if event.phase == "will" then end end function scene:destroy( event ) local sceneGroup = self.view end --------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) return scene

As Brent suggested, you have a scope problem.  When you declare something “local”, its only visible in the block it’s define and any children blocks.  When you do this:

local SummonChampionPassword = native.newTextField(…)

on line 89, the only function  that can see this variable is scene:create().  When you try to remove it in handleCreateChampionScreenButton(), SummonChampionPassword is nil because handleCreateChampionScreenButton() and scene:create() are at the same level. 

The fix is to somewhere near the top of the module and not inside any other block do:

local SummonChampionPassword

(and do the same thing for username).  Then in scene:create() take the word “local” off of the line where you create the new textField.

Rob

That did the trick thanks Rob!

Hi @davidlewis02,

Is the code that you posted the exact “scope” that’s in your project? Meaning, do you declare the native text fields below the function where you remove them? If so, then Lua will not know what objects you are referring to, and it won’t remove them. If that is the case, then the solution is to just fix the scope, for example upvalue declare the references to the native text fields above the function where you remove them.

Best regards,

Brent

Hi Brent sorry for not posting all the code thought it may have just been a syntax thing. I thought I managed to remove the Textfields as the simulator started to show the error and I managed to remove it. But when on my phone the textFields are still not removed. I also get an error now when going to my forgot password screen > back to login then press summon champion says Im trying to remove textFild with nil value. Been my first week so I may well be structuring things wrong (sorry for wall of text :D):

-------------------------userlogin.lua-------------------------------------------------------------------- local composer = require( "composer" )local scene = composer.newScene()local widget = require( "widget" )local utility = require( "utility" )local ads = require( "ads" )local paramslocal myData = require( "mydata" ) &nbsp;&nbsp; --SummonChampionUsername&nbsp;&nbsp; local SummonChampionUsername = native.newTextField(display.contentCenterX\*1, display.contentCenterY \* 0.85, display.contentWidth /3, display.contentHeight/9)&nbsp;&nbsp; SummonChampionUsername.placeholder = "(Email)"&nbsp;&nbsp; SummonChampionUsername:setTextColor( 0, 0, 0 )&nbsp;&nbsp; SummonChampionUsername.isEditable = true&nbsp;&nbsp; --sceneGroup:insert( SummonChampionUsername )&nbsp;&nbsp;&nbsp;&nbsp; --SummonChampionPassword&nbsp;&nbsp; local SummonChampionPassword = native.newTextField(display.contentCenterX\*1, display.contentCenterY \* 1.1, display.contentWidth /3, display.contentHeight/9)&nbsp;&nbsp; SummonChampionPassword.placeholder = "(Password)"&nbsp;&nbsp; SummonChampionPassword:setTextColor( 0, 0, 0 )&nbsp;&nbsp; SummonChampionPassword.isEditable = true&nbsp;&nbsp; --sceneGroup:insert( SummonChampionPassword )&nbsp;&nbsp;local function handleSummonChampionButtonEvent( event )&nbsp;&nbsp;&nbsp; if ( "ended" == event.phase ) then&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SummonChampionUsername:removeSelf()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SummonChampionPassword:removeSelf()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; composer.removeScene( "userlogin", true )&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; composer.gotoScene("menu", { effect = "crossFade", time = 333 })&nbsp;&nbsp;&nbsp; endend local function handleCreateChampionScreenButton( event )&nbsp;&nbsp;&nbsp; if ( "ended" == event.phase ) then&nbsp;&nbsp;&nbsp;&nbsp; SummonChampionUsername:removeSelf()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SummonChampionPassword:removeSelf()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; composer.removeScene( "userlogin", true )&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; composer.gotoScene("createuser", { effect = "crossFade", time = 333 })&nbsp;&nbsp;&nbsp; endend local function handleCreateForgotPasswordScreenButton( event )&nbsp;&nbsp;&nbsp; if ( "ended" == event.phase ) then&nbsp;&nbsp;&nbsp;&nbsp; SummonChampionUsername:removeSelf()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SummonChampionPassword:removeSelf()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; composer.removeScene( "userlogin", true )&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; composer.gotoScene("ForgotPassword", { effect = "crossFade", time = 333 })&nbsp;&nbsp;&nbsp; endend local function onRememberMeCheckBox( event )&nbsp;&nbsp;&nbsp; local switch = event.target &nbsp;&nbsp; if switch.isOn then&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; switch.isOn = true&nbsp;&nbsp;&nbsp; else&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; switch.isOn = false&nbsp; endend function scene:create( event )&nbsp;&nbsp;&nbsp; local sceneGroup = self.view &nbsp;&nbsp;&nbsp; params = event.params local background = display.newImage( "Background.png", display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight )&nbsp;&nbsp;&nbsp; sceneGroup:insert( background ) &nbsp;&nbsp;&nbsp; -- SummonChampionButtonEvent&nbsp;&nbsp;&nbsp; local SummonChampionButton = widget.newButton({&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; id = "loginbutton2",&nbsp;&nbsp;&nbsp; defaultFile = "SummonChampion.png",&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; onRelease = handleSummonChampionButtonEvent&nbsp;&nbsp;&nbsp;&nbsp; })&nbsp;&nbsp;&nbsp; SummonChampionButton.x = display.contentCenterX \* 1&nbsp;&nbsp;&nbsp; SummonChampionButton.y = display.contentCenterY \* 1.4&nbsp;&nbsp;&nbsp; sceneGroup:insert( SummonChampionButton )&nbsp;&nbsp;&nbsp;&nbsp; --SummonChampionUsername&nbsp;&nbsp; local SummonChampionUsername = native.newTextField(display.contentCenterX\*1, display.contentCenterY \* 0.85, display.contentWidth /3, display.contentHeight/9)&nbsp;&nbsp; SummonChampionUsername.placeholder = "(Email)"&nbsp;&nbsp; SummonChampionUsername:setTextColor( 0, 0, 0 )&nbsp;&nbsp; SummonChampionUsername.isEditable = true&nbsp;&nbsp; sceneGroup:insert( SummonChampionUsername )&nbsp;&nbsp;&nbsp;&nbsp; --SummonChampionPassword&nbsp;&nbsp; local SummonChampionPassword = native.newTextField(display.contentCenterX\*1, display.contentCenterY \* 1.1, display.contentWidth /3, display.contentHeight/9)&nbsp;&nbsp; SummonChampionPassword.placeholder = "(Password)"&nbsp;&nbsp; SummonChampionPassword:setTextColor( 0, 0, 0 )&nbsp;&nbsp; SummonChampionPassword.isEditable = true&nbsp;&nbsp; sceneGroup:insert( SummonChampionPassword )&nbsp;&nbsp;&nbsp;&nbsp; --ForgotPasswordScreen&nbsp;&nbsp;&nbsp; local CreateForgotPasswordScreenButton = widget.newButton({&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; id = "CreateForgotPasswordScreenButton",&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; defaultFile = "forgotpassword.png",&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; onRelease = handleCreateForgotPasswordScreenButton&nbsp;&nbsp;&nbsp; })&nbsp;&nbsp;&nbsp; CreateForgotPasswordScreenButton.x = display.contentCenterX \* 1.5&nbsp;&nbsp;&nbsp; CreateForgotPasswordScreenButton.y = display.contentCenterY \* 1.8&nbsp;&nbsp;&nbsp; sceneGroup:insert( CreateForgotPasswordScreenButton )&nbsp;&nbsp;&nbsp;&nbsp; --CreateChampionScreen&nbsp;&nbsp;&nbsp; local CreateChampionScreenButton = widget.newButton({&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; id = "CreateChampionScreenButton",&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; defaultFile = "createchampionlogin.png",&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; onRelease = handleCreateChampionScreenButton&nbsp;&nbsp;&nbsp; })&nbsp;&nbsp;&nbsp; CreateChampionScreenButton.x = display.contentCenterX \* 0.5&nbsp;&nbsp;&nbsp; CreateChampionScreenButton.y = display.contentCenterY \* 1.8&nbsp;&nbsp;&nbsp; sceneGroup:insert( CreateChampionScreenButton )&nbsp;&nbsp;&nbsp;&nbsp; --RememberMe&nbsp;&nbsp;&nbsp;&nbsp; local RememberMe = widget.newButton({&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; id = "rememberme",&nbsp;&nbsp;&nbsp; defaultFile = "rememberme.png"&nbsp;&nbsp;&nbsp;&nbsp; })&nbsp;&nbsp;&nbsp; RememberMe.x = display.contentCenterX \* 0.95&nbsp;&nbsp;&nbsp; RememberMe.y = display.contentCenterY \* 1.6&nbsp;&nbsp;&nbsp; sceneGroup:insert( RememberMe )&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --RememberMeCheckBox&nbsp;&nbsp; local RememberMeCheckBox = widget.newSwitch&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; left = display.contentCenterX \* 1.15,&nbsp;&nbsp;&nbsp; top = display.contentCenterY \* 1.5,&nbsp;&nbsp;&nbsp; style = "checkbox",&nbsp;&nbsp;&nbsp; id = "RememberMeCheckBox",&nbsp;&nbsp;&nbsp; initialSwitchState = true,&nbsp;&nbsp;&nbsp; onPress = onRememberMeCheckBox&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; sceneGroup:insert( RememberMeCheckBox )&nbsp;&nbsp; &nbsp;end&nbsp; function scene:show( event )&nbsp;&nbsp;&nbsp; local sceneGroup = self.view&nbsp;&nbsp;&nbsp; params = event.params&nbsp;&nbsp;&nbsp; if event.phase == "did" then&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; endend function scene:hide( event )&nbsp;&nbsp;&nbsp; local sceneGroup = self.view&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if event.phase == "will" then&nbsp;&nbsp;&nbsp; end end function scene:destroy( event )&nbsp;&nbsp;&nbsp; local sceneGroup = self.view&nbsp;&nbsp;&nbsp;end ----------------------------------------------------------------------------------- END OF YOUR IMPLEMENTATION---------------------------------------------------------------------------------scene:addEventListener( "create", scene )scene:addEventListener( "show", scene )scene:addEventListener( "hide", scene )scene:addEventListener( "destroy", scene )return scene ---------------------------ForgotPassword.lua------------------------------------------------------ local composer = require( "composer" )local scene = composer.newScene()local widget = require( "widget" )local utility = require( "utility" )local ads = require( "ads" )local paramslocal myData = require( "mydata" ) local function handleRetrievePasswordButton( event )&nbsp;&nbsp;&nbsp; if ( "ended" == event.phase ) then&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; composer.removeScene( "ForgotPassword", true )&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; composer.gotoScene("userlogin", { effect = "crossFade", time = 333 })&nbsp;&nbsp;&nbsp; endend local function handleReturntoLoginScreenButton( event )&nbsp;&nbsp;&nbsp; if ( "ended" == event.phase ) then&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; composer.removeScene( "ForgotPassword", true )&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; composer.gotoScene("userlogin", { effect = "crossFade", time = 333 })&nbsp;&nbsp;&nbsp; endend function scene:create( event )&nbsp;&nbsp;&nbsp; local sceneGroup = self.view &nbsp;&nbsp;&nbsp; params = event.params&nbsp;&nbsp;&nbsp;local background = display.newImage( "Background.png", display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight )&nbsp;&nbsp;&nbsp; sceneGroup:insert( background )&nbsp;&nbsp;&nbsp;&nbsp; --ForgotPasswordEmail&nbsp;&nbsp;&nbsp;&nbsp; local ForgotPasswordEmail = native.newTextField(display.contentCenterX\*1, display.contentCenterY \* 1.2, display.contentWidth /3.5, display.contentHeight/11)&nbsp;&nbsp; ForgotPasswordEmail:setTextColor( 1, 1, 1 )&nbsp;&nbsp; ForgotPasswordEmail.isEditable = true&nbsp;&nbsp; sceneGroup:insert( ForgotPasswordEmail ) &nbsp;&nbsp;&nbsp; -- RetrievePasswordButton&nbsp;&nbsp;&nbsp; local RetrievePasswordButton = widget.newButton({&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; id = "RetrievePasswordButton",&nbsp;&nbsp;defaultFile = "retrievepassword.png",&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; onRelease = handleRetrievePasswordButton&nbsp;&nbsp;&nbsp; })&nbsp;&nbsp;&nbsp; RetrievePasswordButton.x = display.contentCenterX&nbsp;&nbsp;&nbsp; RetrievePasswordButton.y = display.contentCenterY \*1.4&nbsp;&nbsp;&nbsp; sceneGroup:insert( RetrievePasswordButton )&nbsp;&nbsp;&nbsp;&nbsp; -- Return to Login Screen&nbsp;&nbsp;&nbsp; local ReturntoLoginScreenButton = widget.newButton({&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; id = "ReturntoLoginScreenButton",&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; defaultFile ="backtologin.png",&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; onRelease = handleReturntoLoginScreenButton&nbsp;&nbsp;&nbsp; })&nbsp;&nbsp;&nbsp; ReturntoLoginScreenButton.x = display.contentCenterX&nbsp;&nbsp;&nbsp; ReturntoLoginScreenButton.y = display.contentCenterY \*1.7&nbsp;&nbsp;&nbsp; sceneGroup:insert( ReturntoLoginScreenButton ) end function scene:show( event )&nbsp;&nbsp;&nbsp; local sceneGroup = self.view &nbsp;&nbsp;&nbsp; params = event.params &nbsp;&nbsp;&nbsp; if event.phase == "did" then&nbsp;&nbsp;&nbsp; endend function scene:hide( event )&nbsp;&nbsp;&nbsp; local sceneGroup = self.view&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if event.phase == "will" then&nbsp;&nbsp;&nbsp; end end function scene:destroy( event )&nbsp;&nbsp;&nbsp; local sceneGroup = self.view&nbsp;&nbsp;&nbsp;end ----------------------------------------------------------------------------------- END OF YOUR IMPLEMENTATION---------------------------------------------------------------------------------scene:addEventListener( "create", scene )scene:addEventListener( "show", scene )scene:addEventListener( "hide", scene )scene:addEventListener( "destroy", scene )return scene

Please edit your post, highlight your code and click on the <> tag in the edit bar so your code highlights correctly.

Thanks

Rob

Hi Rob edited as requested will make sure I do this from now on.

Thanks

Well that didn’t help.  In fact it made it worse.  In the future, when pasting your code in, use the <>, but perhaps going back and editing an already posted block of code reformatted the code poorly.

Rob

Apologies Rob have adjusted:

-----------userlogin.lua----------------- local composer = require( "composer" ) local scene = composer.newScene() local widget = require( "widget" ) local utility = require( "utility" ) local ads = require( "ads" ) local params local myData = require( "mydata" ) --SummonChampionUsername local SummonChampionUsername = native.newTextField(display.contentCenterX\*1, display.contentCenterY \* 0.85, display.contentWidth /3, display.contentHeight/9) SummonChampionUsername.placeholder = "(Email)" SummonChampionUsername:setTextColor( 0, 0, 0 ) SummonChampionUsername.isEditable = true --sceneGroup:insert( SummonChampionUsername ) --SummonChampionPassword local SummonChampionPassword = native.newTextField(display.contentCenterX\*1, display.contentCenterY \* 1.1, display.contentWidth /3, display.contentHeight/9) SummonChampionPassword.placeholder = "(Password)" SummonChampionPassword:setTextColor( 0, 0, 0 ) SummonChampionPassword.isEditable = true --sceneGroup:insert( SummonChampionPassword ) local function handleSummonChampionButtonEvent( event ) if ( "ended" == event.phase ) then SummonChampionUsername:removeSelf() SummonChampionPassword:removeSelf() composer.removeScene( "userlogin", true ) composer.gotoScene("menu", { effect = "crossFade", time = 333 }) end end local function handleCreateChampionScreenButton( event ) if ( "ended" == event.phase ) then SummonChampionUsername:removeSelf() SummonChampionPassword:removeSelf() composer.removeScene( "userlogin", true ) composer.gotoScene("createuser", { effect = "crossFade", time = 333 }) end end local function handleCreateForgotPasswordScreenButton( event ) if ( "ended" == event.phase ) then SummonChampionUsername:removeSelf() SummonChampionPassword:removeSelf() composer.removeScene( "userlogin", true ) composer.gotoScene("ForgotPassword", { effect = "crossFade", time = 333 }) end end local function onRememberMeCheckBox( event ) local switch = event.target if switch.isOn then switch.isOn = true else switch.isOn = false end end function scene:create( event ) local sceneGroup = self.view params = event.params local background = display.newImage( "Background.png", display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight ) sceneGroup:insert( background ) -- SummonChampionButtonEvent local SummonChampionButton = widget.newButton({ id = "loginbutton2", defaultFile = "SummonChampion.png", onRelease = handleSummonChampionButtonEvent }) SummonChampionButton.x = display.contentCenterX \* 1 SummonChampionButton.y = display.contentCenterY \* 1.4 sceneGroup:insert( SummonChampionButton ) --SummonChampionUsername local SummonChampionUsername = native.newTextField(display.contentCenterX\*1, display.contentCenterY \* 0.85, display.contentWidth /3, display.contentHeight/9) SummonChampionUsername.placeholder = "(Email)" SummonChampionUsername:setTextColor( 0, 0, 0 ) SummonChampionUsername.isEditable = true sceneGroup:insert( SummonChampionUsername ) --SummonChampionPassword local SummonChampionPassword = native.newTextField(display.contentCenterX\*1, display.contentCenterY \* 1.1, display.contentWidth /3, display.contentHeight/9) SummonChampionPassword.placeholder = "(Password)" SummonChampionPassword:setTextColor( 0, 0, 0 ) SummonChampionPassword.isEditable = true sceneGroup:insert( SummonChampionPassword ) --ForgotPasswordScreen local CreateForgotPasswordScreenButton = widget.newButton({ id = "CreateForgotPasswordScreenButton", defaultFile = "forgotpassword.png", onRelease = handleCreateForgotPasswordScreenButton }) CreateForgotPasswordScreenButton.x = display.contentCenterX \* 1.5 CreateForgotPasswordScreenButton.y = display.contentCenterY \* 1.8 sceneGroup:insert( CreateForgotPasswordScreenButton ) --CreateChampionScreen local CreateChampionScreenButton = widget.newButton({ id = "CreateChampionScreenButton", defaultFile = "createchampionlogin.png", onRelease = handleCreateChampionScreenButton }) CreateChampionScreenButton.x = display.contentCenterX \* 0.5 CreateChampionScreenButton.y = display.contentCenterY \* 1.8 sceneGroup:insert( CreateChampionScreenButton ) --RememberMe local RememberMe = widget.newButton({ id = "rememberme", defaultFile = "rememberme.png" }) RememberMe.x = display.contentCenterX \* 0.95 RememberMe.y = display.contentCenterY \* 1.6 sceneGroup:insert( RememberMe ) --RememberMeCheckBox local RememberMeCheckBox = widget.newSwitch { left = display.contentCenterX \* 1.15, top = display.contentCenterY \* 1.5, style = "checkbox", id = "RememberMeCheckBox", initialSwitchState = true, onPress = onRememberMeCheckBox } sceneGroup:insert( RememberMeCheckBox ) end function scene:show( event ) local sceneGroup = self.view params = event.params if event.phase == "did" then end end function scene:hide( event ) local sceneGroup = self.view if event.phase == "will" then end end function scene:destroy( event ) local sceneGroup = self.view end --------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) return scene --------------forgotpassword.lua----------------- local composer = require( "composer" ) local scene = composer.newScene() local widget = require( "widget" ) local utility = require( "utility" ) local ads = require( "ads" ) local params local myData = require( "mydata" ) local function handleRetrievePasswordButton( event ) if ( "ended" == event.phase ) then composer.removeScene( "ForgotPassword", true ) composer.gotoScene("userlogin", { effect = "crossFade", time = 333 }) end end local function handleReturntoLoginScreenButton( event ) if ( "ended" == event.phase ) then composer.removeScene( "ForgotPassword", true ) composer.gotoScene("userlogin", { effect = "crossFade", time = 333 }) end end function scene:create( event ) local sceneGroup = self.view params = event.params local background = display.newImage( "Background.png", display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight ) sceneGroup:insert( background ) --ForgotPasswordEmail local ForgotPasswordEmail = native.newTextField(display.contentCenterX\*1, display.contentCenterY \* 1.2, display.contentWidth /3.5, display.contentHeight/11) ForgotPasswordEmail:setTextColor( 1, 1, 1 ) ForgotPasswordEmail.isEditable = true sceneGroup:insert( ForgotPasswordEmail ) -- RetrievePasswordButton local RetrievePasswordButton = widget.newButton({ id = "RetrievePasswordButton", defaultFile = "retrievepassword.png", onRelease = handleRetrievePasswordButton }) RetrievePasswordButton.x = display.contentCenterX RetrievePasswordButton.y = display.contentCenterY \*1.4 sceneGroup:insert( RetrievePasswordButton ) -- Return to Login Screen local ReturntoLoginScreenButton = widget.newButton({ id = "ReturntoLoginScreenButton", defaultFile ="backtologin.png", onRelease = handleReturntoLoginScreenButton }) ReturntoLoginScreenButton.x = display.contentCenterX ReturntoLoginScreenButton.y = display.contentCenterY \*1.7 sceneGroup:insert( ReturntoLoginScreenButton ) end function scene:show( event ) local sceneGroup = self.view params = event.params if event.phase == "did" then end end function scene:hide( event ) local sceneGroup = self.view if event.phase == "will" then end end function scene:destroy( event ) local sceneGroup = self.view end --------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) return scene

As Brent suggested, you have a scope problem.  When you declare something “local”, its only visible in the block it’s define and any children blocks.  When you do this:

local SummonChampionPassword = native.newTextField(…)

on line 89, the only function  that can see this variable is scene:create().  When you try to remove it in handleCreateChampionScreenButton(), SummonChampionPassword is nil because handleCreateChampionScreenButton() and scene:create() are at the same level. 

The fix is to somewhere near the top of the module and not inside any other block do:

local SummonChampionPassword

(and do the same thing for username).  Then in scene:create() take the word “local” off of the line where you create the new textField.

Rob

That did the trick thanks Rob!