Home / Topic / Problem with Text Input Replacement

Problem with Text Input Replacement

Home Kwiksher Forums Help me! Problem with Text Input Replacement

Viewing 9 posts - 1 through 9 (of 9 total)
  • #83956

    Hi Yamamoto,
    I am still having problems with Text Input Replacement. I submitted a question to the forum a few months ago about this issue but was not able to get an answer.

    I have two issues that I need help with:

    1. I have the text input replacement save into a variable. I set that variable up to save. However, when I leave the screen and come back, the text I inputed is gone.

    2. When I use the text input replacement I do get a text box but it does not show up in the same space as the item it is replacing and the box has a white background. I have been able to create a work around for this with external code but then I run into the same problem of the text not saving.

    Is it possible for you to do a tutorial on this?

    Thank you!
    Christi

    Yamamoto
    Keymaster
    #83960

    I tested it and it is a bug of Kwik. You can work around by the following external codes to set the value to the input text field.

    Your_Variable_Name = kwkVarCheck(“Your_Variable_Name”)
    layer.Your_InputBox_Name.text = Your_Variable_Name

    The white background and the positioning issues are worked around by the following external codes

    layer.Your_InputBox_Name.hasBackground = false
    layer.Your_InputBox_Name.anchorY = 0

    I will fix it in next release

    #83963

    Hi Yamamoto,
    Thank you for your response.
    For some reason it is still not saving the text that was input as the team name.
    I am wondering if it is missing a line like this: saveKwikVars({“team1input”,team1input})
    If so, where should I add it?

    I added in the external code you suggested “after all variables” and set it to save.
    My variable for the inputed text is “team1input”
    My text layer that I am using for the keyboard replacement is “tm1box”

    This is what the code looks like :

    -- Code created by Kwik - Copyright: kwiksher.com 
    -- Version: 3.5.2 
    -- Project: CharadesV2, published on Mon Jun 29 2015 14:29:25 GMT-0400 
    local composer = require( "composer" ) 
    local scene = composer.newScene() 
    
    -- External libraries 
    
    -- Initial settings and checkings 
    local numPages = 2 -- number of pages in the project 
    local sceneGroup = nil -- main group for all page elements
    local W = display.contentWidth; -- full width of the page
    local H = display.contentHeight; -- full height of the page
    
         
    local curPage = 2 -- number of the current page 
    
    -- Button names 
    local but_gohome
    
    -- Variables names 
    local team1input = "" --  
    math.randomseed(os.time()) 
    
    -- All layers on a table 
    local layer = {} 
    
    -- All audio files on a table 
    local allAudios = {} 
    allAudios.kAutoPlay = composer.kAutoPlay 
    
    -- Calculates anchor points 
    local function repositionAnchor( object, newAnchorX, newAnchorY ) 
         local origX = object.x; local origY = object.y 
         if newAnchorX ~= 0.5 or newAnchorY ~= 0.5 then 
             local width = object.width; local height = object.height 
             local xCoord = width * (newAnchorX - .5)  
             local yCoord = height * (newAnchorY - .5) 
             object.x = origX + xCoord; object.y = origY + yCoord 
             object.oriX = object.x; object.oriY = object.y   
         end 
    end 
    
    -- Called when the scene's view does not exist:  
    function scene:create( event )  
        -- view is not yet visible  
        local sceneGroup = self.view  
        
        -- BEFORE variables 
        team1input = "" --  
           -- Check if variable has a pre-saved content 
           if kwkVarCheck("team1input") ~= nil then  
            team1input = kwkVarCheck("team1input") 
           end  
    
        -- Capture and set group position 
        local function groupPos(obj) 
           local minX, minY 
           for i = 1, obj.numChildren do 
              local currentRecord = obj[ i ] 
              if i == 1 then 
                 minX = currentRecord.x - currentRecord.contentWidth * 0.5 
                 minY = currentRecord.y - currentRecord.contentHeight * 0.5 
              end 
              local mX = currentRecord.x - currentRecord.contentWidth * 0.5 
              if mX < minX then 
                 minX = mX 
              end 
              local mY = currentRecord.y - currentRecord.contentHeight * 0.5 
              if mY < minY then 
                 minY = mY 
              end 
           end 
           obj.x = minX + obj.contentWidth * 0.5 
           obj.y = minY + obj.contentHeight * 0.5 
        end 
    
        -- Multilingual items 
    
        -- (TOP) External code will render here 
    
        -- kwkplay_bg positioning 
           layer.kwkplay_bg = display.newImageRect( composer.imgDir.. "kwkplay_bg.png", 1536, 2048 ); 
           layer.kwkplay_bg.x = 768; layer.kwkplay_bg.y = 1024; layer.kwkplay_bg.alpha = 1; layer.kwkplay_bg.oldAlpha = 1 
           layer.kwkplay_bg.oriX = layer.kwkplay_bg.x; layer.kwkplay_bg.oriY = layer.kwkplay_bg.y 
           layer.kwkplay_bg.oriXs = layer.kwkplay_bg.xScale; layer.kwkplay_bg.oriYs = layer.kwkplay_bg.yScale 
           layer.kwkplay_bg.name = "kwkplay_bg" 
           sceneGroup:insert( 1, layer.kwkplay_bg); sceneGroup.kwkplay_bg = layer.kwkplay_bg 
    
        -- kwkabout positioning 
           layer.kwkabout = display.newImageRect( composer.imgDir.. "kwkabout.png", 250, 250 ); 
           layer.kwkabout.x = 1198; layer.kwkabout.y = 1839; layer.kwkabout.alpha = 1; layer.kwkabout.oldAlpha = 1 
           layer.kwkabout.oriX = layer.kwkabout.x; layer.kwkabout.oriY = layer.kwkabout.y 
           layer.kwkabout.oriXs = layer.kwkabout.xScale; layer.kwkabout.oriYs = layer.kwkabout.yScale 
           layer.kwkabout.name = "kwkabout" 
           sceneGroup:insert( layer.kwkabout); sceneGroup.kwkabout = layer.kwkabout 
    
        -- kwksettings positioning 
           layer.kwksettings = display.newImageRect( composer.imgDir.. "kwksettings.png", 250, 250 ); 
           layer.kwksettings.x = 915; layer.kwksettings.y = 1839; layer.kwksettings.alpha = 1; layer.kwksettings.oldAlpha = 1 
           layer.kwksettings.oriX = layer.kwksettings.x; layer.kwksettings.oriY = layer.kwksettings.y 
           layer.kwksettings.oriXs = layer.kwksettings.xScale; layer.kwksettings.oriYs = layer.kwksettings.yScale 
           layer.kwksettings.name = "kwksettings" 
           sceneGroup:insert( layer.kwksettings); sceneGroup.kwksettings = layer.kwksettings 
    
        -- kwkplay positioning 
           layer.kwkplay = display.newImageRect( composer.imgDir.. "kwkplay.png", 250, 250 ); 
           layer.kwkplay.x = 632; layer.kwkplay.y = 1839; layer.kwkplay.alpha = 1; layer.kwkplay.oldAlpha = 1 
           layer.kwkplay.oriX = layer.kwkplay.x; layer.kwkplay.oriY = layer.kwkplay.y 
           layer.kwkplay.oriXs = layer.kwkplay.xScale; layer.kwkplay.oriYs = layer.kwkplay.yScale 
           layer.kwkplay.name = "kwkplay" 
           sceneGroup:insert( layer.kwkplay); sceneGroup.kwkplay = layer.kwkplay 
    
        -- kwkhome positioning 
           layer.kwkhome = display.newImageRect( composer.imgDir.. "kwkhome.png", 250, 250 ); 
           layer.kwkhome.x = 349; layer.kwkhome.y = 1839; layer.kwkhome.alpha = 1; layer.kwkhome.oldAlpha = 1 
           layer.kwkhome.oriX = layer.kwkhome.x; layer.kwkhome.oriY = layer.kwkhome.y 
           layer.kwkhome.oriXs = layer.kwkhome.xScale; layer.kwkhome.oriYs = layer.kwkhome.yScale 
           layer.kwkhome.name = "kwkhome" 
           sceneGroup:insert(layer.kwkhome); sceneGroup.kwkhome = layer.kwkhome 
    
        -- play_gobtn positioning 
           layer.play_gobtn = display.newImageRect( composer.imgDir.. "p2_play_gobtn.png", 902, 222 ); 
           layer.play_gobtn.x = 768; layer.play_gobtn.y = 1307; layer.play_gobtn.alpha = 1; layer.play_gobtn.oldAlpha = 1 
           layer.play_gobtn.oriX = layer.play_gobtn.x; layer.play_gobtn.oriY = layer.play_gobtn.y 
           layer.play_gobtn.oriXs = layer.play_gobtn.xScale; layer.play_gobtn.oriYs = layer.play_gobtn.yScale 
           layer.play_gobtn.name = "play_gobtn" 
           sceneGroup:insert( layer.play_gobtn); sceneGroup.play_gobtn = layer.play_gobtn 
    
        -- play_cardbk positioning 
           layer.play_cardbk = display.newImageRect( composer.imgDir.. "p2_play_cardbk.png", 962, 692 ); 
           layer.play_cardbk.x = 769; layer.play_cardbk.y = 475; layer.play_cardbk.alpha = 1; layer.play_cardbk.oldAlpha = 1 
           layer.play_cardbk.oriX = layer.play_cardbk.x; layer.play_cardbk.oriY = layer.play_cardbk.y 
           layer.play_cardbk.oriXs = layer.play_cardbk.xScale; layer.play_cardbk.oriYs = layer.play_cardbk.yScale 
           layer.play_cardbk.name = "play_cardbk" 
           sceneGroup:insert( layer.play_cardbk); sceneGroup.play_cardbk = layer.play_cardbk 
    
        -- play_t2bg positioning 
           layer.play_t2bg = display.newImageRect( composer.imgDir.. "p2_play_t2bg.png", 1044, 156 ); 
           layer.play_t2bg.x = 780; layer.play_t2bg.y = 1079; layer.play_t2bg.alpha = 1; layer.play_t2bg.oldAlpha = 1 
           layer.play_t2bg.oriX = layer.play_t2bg.x; layer.play_t2bg.oriY = layer.play_t2bg.y 
           layer.play_t2bg.oriXs = layer.play_t2bg.xScale; layer.play_t2bg.oriYs = layer.play_t2bg.yScale 
           layer.play_t2bg.name = "play_t2bg" 
           sceneGroup:insert( layer.play_t2bg); sceneGroup.play_t2bg = layer.play_t2bg 
    
        -- play_t2minus positioning 
           layer.play_t2minus = display.newImageRect( composer.imgDir.. "p2_play_t2minus.png", 110, 110 ); 
           layer.play_t2minus.x = 1191; layer.play_t2minus.y = 1074; layer.play_t2minus.alpha = 1; layer.play_t2minus.oldAlpha = 1 
           layer.play_t2minus.oriX = layer.play_t2minus.x; layer.play_t2minus.oriY = layer.play_t2minus.y 
           layer.play_t2minus.oriXs = layer.play_t2minus.xScale; layer.play_t2minus.oriYs = layer.play_t2minus.yScale 
           layer.play_t2minus.name = "play_t2minus" 
           sceneGroup:insert( layer.play_t2minus); sceneGroup.play_t2minus = layer.play_t2minus 
    
        -- play_t2plus positioning 
           layer.play_t2plus = display.newImageRect( composer.imgDir.. "p2_play_t2plus.png", 110, 110 ); 
           layer.play_t2plus.x = 1054; layer.play_t2plus.y = 1074; layer.play_t2plus.alpha = 1; layer.play_t2plus.oldAlpha = 1 
           layer.play_t2plus.oriX = layer.play_t2plus.x; layer.play_t2plus.oriY = layer.play_t2plus.y 
           layer.play_t2plus.oriXs = layer.play_t2plus.xScale; layer.play_t2plus.oriYs = layer.play_t2plus.yScale 
           layer.play_t2plus.name = "play_t2plus" 
           sceneGroup:insert( layer.play_t2plus); sceneGroup.play_t2plus = layer.play_t2plus 
    
        -- play_t1bg positioning 
           layer.play_t1bg = display.newImageRect( composer.imgDir.. "p2_play_t1bg.png", 1044, 156 ); 
           layer.play_t1bg.x = 780; layer.play_t1bg.y = 915; layer.play_t1bg.alpha = 1; layer.play_t1bg.oldAlpha = 1 
           layer.play_t1bg.oriX = layer.play_t1bg.x; layer.play_t1bg.oriY = layer.play_t1bg.y 
           layer.play_t1bg.oriXs = layer.play_t1bg.xScale; layer.play_t1bg.oriYs = layer.play_t1bg.yScale 
           layer.play_t1bg.name = "play_t1bg" 
           sceneGroup:insert( layer.play_t1bg); sceneGroup.play_t1bg = layer.play_t1bg 
    
        -- play_t1minus positioning 
           layer.play_t1minus = display.newImageRect( composer.imgDir.. "p2_play_t1minus.png", 110, 110 ); 
           layer.play_t1minus.x = 1191; layer.play_t1minus.y = 910; layer.play_t1minus.alpha = 1; layer.play_t1minus.oldAlpha = 1 
           layer.play_t1minus.oriX = layer.play_t1minus.x; layer.play_t1minus.oriY = layer.play_t1minus.y 
           layer.play_t1minus.oriXs = layer.play_t1minus.xScale; layer.play_t1minus.oriYs = layer.play_t1minus.yScale 
           layer.play_t1minus.name = "play_t1minus" 
           sceneGroup:insert( layer.play_t1minus); sceneGroup.play_t1minus = layer.play_t1minus 
    
        -- play_t1plus positioning 
           layer.play_t1plus = display.newImageRect( composer.imgDir.. "p2_play_t1plus.png", 110, 110 ); 
           layer.play_t1plus.x = 1054; layer.play_t1plus.y = 910; layer.play_t1plus.alpha = 1; layer.play_t1plus.oldAlpha = 1 
           layer.play_t1plus.oriX = layer.play_t1plus.x; layer.play_t1plus.oriY = layer.play_t1plus.y 
           layer.play_t1plus.oriXs = layer.play_t1plus.xScale; layer.play_t1plus.oriYs = layer.play_t1plus.yScale 
           layer.play_t1plus.name = "play_t1plus" 
           sceneGroup:insert( layer.play_t1plus); sceneGroup.play_t1plus = layer.play_t1plus 
    
        -- play_howto positioning 
           layer.play_howto = display.newImageRect( composer.imgDir.. "p2_play_howto.png", 320, 158 ); 
           layer.play_howto.x = 392; layer.play_howto.y = 1555; layer.play_howto.alpha = 1; layer.play_howto.oldAlpha = 1 
           layer.play_howto.oriX = layer.play_howto.x; layer.play_howto.oriY = layer.play_howto.y 
           layer.play_howto.oriXs = layer.play_howto.xScale; layer.play_howto.oriYs = layer.play_howto.yScale 
           layer.play_howto.name = "play_howto" 
           sceneGroup:insert( layer.play_howto); sceneGroup.play_howto = layer.play_howto 
    
        -- play_newgame positioning 
           layer.play_newgame = display.newImageRect( composer.imgDir.. "p2_play_newgame.png", 326, 166 ); 
           layer.play_newgame.x = 770; layer.play_newgame.y = 1555; layer.play_newgame.alpha = 1; layer.play_newgame.oldAlpha = 1 
           layer.play_newgame.oriX = layer.play_newgame.x; layer.play_newgame.oriY = layer.play_newgame.y 
           layer.play_newgame.oriXs = layer.play_newgame.xScale; layer.play_newgame.oriYs = layer.play_newgame.yScale 
           layer.play_newgame.name = "play_newgame" 
           sceneGroup:insert( layer.play_newgame); sceneGroup.play_newgame = layer.play_newgame 
    
        -- play_rules positioning 
           layer.play_rules = display.newImageRect( composer.imgDir.. "p2_play_rules.png", 326, 166 ); 
           layer.play_rules.x = 1150; layer.play_rules.y = 1556; layer.play_rules.alpha = 1; layer.play_rules.oldAlpha = 1 
           layer.play_rules.oriX = layer.play_rules.x; layer.play_rules.oriY = layer.play_rules.y 
           layer.play_rules.oriXs = layer.play_rules.xScale; layer.play_rules.oriYs = layer.play_rules.yScale 
           layer.play_rules.name = "play_rules" 
           sceneGroup:insert( layer.play_rules); sceneGroup.play_rules = layer.play_rules 
    
        -- tm1scoretxt positioning 
           layer.tm1scoretxt = display.newImageRect( composer.imgDir.. "p2_tm1scoretxt.png", 29, 43 ); 
           layer.tm1scoretxt.x = 916; layer.tm1scoretxt.y = 911; layer.tm1scoretxt.alpha = 1; layer.tm1scoretxt.oldAlpha = 1 
           layer.tm1scoretxt.oriX = layer.tm1scoretxt.x; layer.tm1scoretxt.oriY = layer.tm1scoretxt.y 
           layer.tm1scoretxt.oriXs = layer.tm1scoretxt.xScale; layer.tm1scoretxt.oriYs = layer.tm1scoretxt.yScale 
           layer.tm1scoretxt.name = "tm1scoretxt" 
           sceneGroup:insert( layer.tm1scoretxt); sceneGroup.tm1scoretxt = layer.tm1scoretxt 
    
        -- tm2scoretxt positioning 
           layer.tm2scoretxt = display.newImageRect( composer.imgDir.. "p2_tm2scoretxt.png", 29, 43 ); 
           layer.tm2scoretxt.x = 916; layer.tm2scoretxt.y = 1075; layer.tm2scoretxt.alpha = 1; layer.tm2scoretxt.oldAlpha = 1 
           layer.tm2scoretxt.oriX = layer.tm2scoretxt.x; layer.tm2scoretxt.oriY = layer.tm2scoretxt.y 
           layer.tm2scoretxt.oriXs = layer.tm2scoretxt.xScale; layer.tm2scoretxt.oriYs = layer.tm2scoretxt.yScale 
           layer.tm2scoretxt.name = "tm2scoretxt" 
           sceneGroup:insert( layer.tm2scoretxt); sceneGroup.tm2scoretxt = layer.tm2scoretxt 
    
        -- tm1box positioning 
           layer.tm1box = native.newTextField( 584, 895, 553, 39 ) 
           layer.tm1box.input = "default" 
           layer.tm1box.anchorX = 0.5; layer.tm1box.anchorY = 0; 
           repositionAnchor(layer.tm1box,0.5,0); 
           layer.tm1box.oriX = layer.tm1box.x; layer.tm1box.oriY = layer.tm1box.y 
           layer.tm1box.oriXs = layer.tm1box.xScale; layer.tm1box.oriYs = layer.tm1box.yScale 
           sceneGroup:insert( layer.tm1box); sceneGroup.tm1box = layer.tm1box 
     
           -- Group(s) creation 
    
           -- AFTER variables 
    
           -- (MIDDLE) External code will render here 
           team1input = kwkVarCheck("team1input")
    layer.tm1box.text = team1input
    layer.tm1box.hasBackground = false
    layer.tm1box.anchorY = 0  
    layer.tm1box.size = 50
    layer.tm1box:setTextColor(1,1,1)
     
    
           -- Repositions according anchor points 
    
    end -- ends scene:create
    
    -- Called when the scene's view is about to 'will/load' or 'did/appear': 
    function scene:show( event ) 
       local sceneGroup = self.view 
    
       if event.phase == "did" then 
          -- purges previous and next scenes 
          local __prevScene = composer.getSceneName( "previous" ) 
          if nil~= __prevScene then composer.removeScene(__prevScene, true) end   
    
          -- Check for previous bookmarks 
           if (tonumber(composer.kBookmark) == 1) then 
              local path = system.pathForFile( "book.txt", system.DocumentsDirectory ) 
              local file = io.open( path, "w+" ) 
              file:write ( curPage.."\n1" ) 
              io.close( file ) 
           end 
    
          -- Check for for auto play settings 
           if (tonumber(composer.kAutoPlay) > 0) then 
             local function act_autoPlay(event) 
               if(curPage < numPages) then 
                  if nil~= composer.getScene( "page_"..curPage+1) then composer.removeScene( "page_"..curPage+1, true) end 
                  if(composer.kBidi == false) then  
                    composer.gotoScene( "page_"..curPage+1, { effect = "fromRight"} ) 
                  else  
                    composer.gotoScene( "page_"..curPage-1, { effect = "fromLeft"} ) 
                  end  
               end 
             end 
             if (tonumber(allAudios.kAutoPlay) > composer.kAutoPlay) then 
                 composer.timerStash.timer_AP = timer.performWithDelay( allAudios.kAutoPlay*1000, act_autoPlay, 1 ) 
             else  
                 composer.timerStash.timer_AP = timer.performWithDelay( composer.kAutoPlay*1000, act_autoPlay, 1 ) 
             end 
           end 
    
            local function fieldHandler_tm1box(event) 
                   if ("began" == event.phase) then  
                   elseif ("ended" == event.phase) then  
                   elseif ("submitted" == event.phase) then  
                      team1input = layer.tm1box.text 
                      native.setKeyboardFocus(nil) 
                   end  
           end 
           layer.tm1box:addEventListener( "userInput", fieldHandler_tm1box ) 
    
           -- Button event listeners 
    
           local function onkwkhomeEvent(event) 
              but_gohome(layer.kwkhome) 
              return true 
           end 
           layer.kwkhome:addEventListener("tap", onkwkhomeEvent ) 
    
           -- Button functions 
           function but_gohome(self) 
                local myClosure_switch35 = function() 
                    local options = { effect = "slideRight" } 
                    if nil~= composer.getScene("page_1") then composer.removeScene("page_1", true) end  
                    if  self.type == "press" then 
                        self:setEnabled(false) 
                    else 
                        self:removeEventListener( "tap", onkwkhomeEvent ) 
                    end 
                    composer.gotoScene( "page_1", options ) 
                end 
                composer.timerStash.newTimer_335 = timer.performWithDelay(0, myClosure_switch35, 1) 
           end 
    
           -- do not swipe this page 
    
           -- (BOTTOM) External code will render here 
       end --ends phase did 
    
    end -- ends scene:show
    
    function scene:hide( event ) 
          -- purges previous and next scenes 
       -- all disposal happens here 
       if event.phase == "will" then 
         composer.reloadCanvas = 0 
         if lineTable then 
            for i=1, #lineTable do 
               lineTable[i]:removeSelf(); lineTable[i] = nil 
            end 
         end 
    
              composer.cancelAllTimers(); 
           saveKwikVars({"team1input",team1input}) 
           layer.tm1box:removeSelf(); layer.tm1box = nil 
       elseif event.phase == "did" then 
              composer.test = nil 
       end 
    end  
    
    function scene:destroy( event ) 
       -- Remove all unecessary composer items 
    end 
    
    scene:addEventListener( "create", scene ) 
    scene:addEventListener( "show", scene ) 
    scene:addEventListener( "hide", scene ) 
    scene:addEventListener( "destroy", scene ) 
    return scene 
    
    Yamamoto
    Keymaster
    #83964

    The external code to be placed after buttons and actions

    then it should be placed in the bottom of scene:show function

    #83965

    I just tried it with that change and it is still not saving. Perhaps the saveKwikVars({“team1input”,team1input}) should be placed within this function?

    local function fieldHandler_tm1box(event) 
                   if ("began" == event.phase) then  
                   elseif ("ended" == event.phase) then  
                   elseif ("submitted" == event.phase) then  
                      team1input = layer.tm1box.text 
                      native.setKeyboardFocus(nil) 
                   end  
           end 
           layer.tm1box:addEventListener( "userInput", fieldHandler_tm1box ) 

    I reached out to Corona as well for help and this was Rob’s response:

    Okay. I’m glad you’re in contact with Kwik. I don’t see where you’re doing anything with the data:
    local function fieldHandler_tm1box(event)
    if (“began” == event.phase) then
    elseif (“ended” == event.phase) then
    elseif (“submitted” == event.phase) then
    team1input = layer.tm1box.text

    native.setKeyboardFocus(nil)
    end
    end
    You capture team1input from the text box, but you don’t save it. Normally you would put code in that function to save it.

    Rob

    I see the – saveKwikVars({“team1input”,team1input}) – in my code but it does not show up until the scene:hide section.

    Here is the code revised with the variable saved after buttons and actions:

    -- Code created by Kwik - Copyright: kwiksher.com 
    -- Version: 3.5.2 
    -- Project: CharadesV2, published on Mon Jun 29 2015 22:01:04 GMT-0400 
    local composer = require( "composer" ) 
    local scene = composer.newScene() 
    
    -- External libraries 
    
    -- Initial settings and checkings 
    local numPages = 2 -- number of pages in the project 
    local sceneGroup = nil -- main group for all page elements
    local W = display.contentWidth; -- full width of the page
    local H = display.contentHeight; -- full height of the page
    
         
    local curPage = 2 -- number of the current page 
    
    -- Button names 
    local but_gohome
    
    -- Variables names 
    local team1input = "" --  
    math.randomseed(os.time()) 
    
    -- All layers on a table 
    local layer = {} 
    
    -- All audio files on a table 
    local allAudios = {} 
    allAudios.kAutoPlay = composer.kAutoPlay 
    
    -- Calculates anchor points 
    local function repositionAnchor( object, newAnchorX, newAnchorY ) 
         local origX = object.x; local origY = object.y 
         if newAnchorX ~= 0.5 or newAnchorY ~= 0.5 then 
             local width = object.width; local height = object.height 
             local xCoord = width * (newAnchorX - .5)  
             local yCoord = height * (newAnchorY - .5) 
             object.x = origX + xCoord; object.y = origY + yCoord 
             object.oriX = object.x; object.oriY = object.y   
         end 
    end 
    
    -- Called when the scene's view does not exist:  
    function scene:create( event )  
        -- view is not yet visible  
        local sceneGroup = self.view  
        
        -- BEFORE variables 
        team1input = "" --  
           -- Check if variable has a pre-saved content 
           if kwkVarCheck("team1input") ~= nil then  
            team1input = kwkVarCheck("team1input") 
           end  
    
        -- Capture and set group position 
        local function groupPos(obj) 
           local minX, minY 
           for i = 1, obj.numChildren do 
              local currentRecord = obj[ i ] 
              if i == 1 then 
                 minX = currentRecord.x - currentRecord.contentWidth * 0.5 
                 minY = currentRecord.y - currentRecord.contentHeight * 0.5 
              end 
              local mX = currentRecord.x - currentRecord.contentWidth * 0.5 
              if mX < minX then 
                 minX = mX 
              end 
              local mY = currentRecord.y - currentRecord.contentHeight * 0.5 
              if mY < minY then 
                 minY = mY 
              end 
           end 
           obj.x = minX + obj.contentWidth * 0.5 
           obj.y = minY + obj.contentHeight * 0.5 
        end 
    
        -- Multilingual items 
    
        -- (TOP) External code will render here 
    
        -- kwkplay_bg positioning 
           layer.kwkplay_bg = display.newImageRect( composer.imgDir.. "kwkplay_bg.png", 1536, 2048 ); 
           layer.kwkplay_bg.x = 768; layer.kwkplay_bg.y = 1024; layer.kwkplay_bg.alpha = 1; layer.kwkplay_bg.oldAlpha = 1 
           layer.kwkplay_bg.oriX = layer.kwkplay_bg.x; layer.kwkplay_bg.oriY = layer.kwkplay_bg.y 
           layer.kwkplay_bg.oriXs = layer.kwkplay_bg.xScale; layer.kwkplay_bg.oriYs = layer.kwkplay_bg.yScale 
           layer.kwkplay_bg.name = "kwkplay_bg" 
           sceneGroup:insert( 1, layer.kwkplay_bg); sceneGroup.kwkplay_bg = layer.kwkplay_bg 
    
        -- kwkabout positioning 
           layer.kwkabout = display.newImageRect( composer.imgDir.. "kwkabout.png", 250, 250 ); 
           layer.kwkabout.x = 1198; layer.kwkabout.y = 1839; layer.kwkabout.alpha = 1; layer.kwkabout.oldAlpha = 1 
           layer.kwkabout.oriX = layer.kwkabout.x; layer.kwkabout.oriY = layer.kwkabout.y 
           layer.kwkabout.oriXs = layer.kwkabout.xScale; layer.kwkabout.oriYs = layer.kwkabout.yScale 
           layer.kwkabout.name = "kwkabout" 
           sceneGroup:insert( layer.kwkabout); sceneGroup.kwkabout = layer.kwkabout 
    
        -- kwksettings positioning 
           layer.kwksettings = display.newImageRect( composer.imgDir.. "kwksettings.png", 250, 250 ); 
           layer.kwksettings.x = 915; layer.kwksettings.y = 1839; layer.kwksettings.alpha = 1; layer.kwksettings.oldAlpha = 1 
           layer.kwksettings.oriX = layer.kwksettings.x; layer.kwksettings.oriY = layer.kwksettings.y 
           layer.kwksettings.oriXs = layer.kwksettings.xScale; layer.kwksettings.oriYs = layer.kwksettings.yScale 
           layer.kwksettings.name = "kwksettings" 
           sceneGroup:insert( layer.kwksettings); sceneGroup.kwksettings = layer.kwksettings 
    
        -- kwkplay positioning 
           layer.kwkplay = display.newImageRect( composer.imgDir.. "kwkplay.png", 250, 250 ); 
           layer.kwkplay.x = 632; layer.kwkplay.y = 1839; layer.kwkplay.alpha = 1; layer.kwkplay.oldAlpha = 1 
           layer.kwkplay.oriX = layer.kwkplay.x; layer.kwkplay.oriY = layer.kwkplay.y 
           layer.kwkplay.oriXs = layer.kwkplay.xScale; layer.kwkplay.oriYs = layer.kwkplay.yScale 
           layer.kwkplay.name = "kwkplay" 
           sceneGroup:insert( layer.kwkplay); sceneGroup.kwkplay = layer.kwkplay 
    
        -- kwkhome positioning 
           layer.kwkhome = display.newImageRect( composer.imgDir.. "kwkhome.png", 250, 250 ); 
           layer.kwkhome.x = 349; layer.kwkhome.y = 1839; layer.kwkhome.alpha = 1; layer.kwkhome.oldAlpha = 1 
           layer.kwkhome.oriX = layer.kwkhome.x; layer.kwkhome.oriY = layer.kwkhome.y 
           layer.kwkhome.oriXs = layer.kwkhome.xScale; layer.kwkhome.oriYs = layer.kwkhome.yScale 
           layer.kwkhome.name = "kwkhome" 
           sceneGroup:insert(layer.kwkhome); sceneGroup.kwkhome = layer.kwkhome 
    
        -- play_gobtn positioning 
           layer.play_gobtn = display.newImageRect( composer.imgDir.. "p2_play_gobtn.png", 902, 222 ); 
           layer.play_gobtn.x = 768; layer.play_gobtn.y = 1307; layer.play_gobtn.alpha = 1; layer.play_gobtn.oldAlpha = 1 
           layer.play_gobtn.oriX = layer.play_gobtn.x; layer.play_gobtn.oriY = layer.play_gobtn.y 
           layer.play_gobtn.oriXs = layer.play_gobtn.xScale; layer.play_gobtn.oriYs = layer.play_gobtn.yScale 
           layer.play_gobtn.name = "play_gobtn" 
           sceneGroup:insert( layer.play_gobtn); sceneGroup.play_gobtn = layer.play_gobtn 
    
        -- play_cardbk positioning 
           layer.play_cardbk = display.newImageRect( composer.imgDir.. "p2_play_cardbk.png", 962, 692 ); 
           layer.play_cardbk.x = 769; layer.play_cardbk.y = 475; layer.play_cardbk.alpha = 1; layer.play_cardbk.oldAlpha = 1 
           layer.play_cardbk.oriX = layer.play_cardbk.x; layer.play_cardbk.oriY = layer.play_cardbk.y 
           layer.play_cardbk.oriXs = layer.play_cardbk.xScale; layer.play_cardbk.oriYs = layer.play_cardbk.yScale 
           layer.play_cardbk.name = "play_cardbk" 
           sceneGroup:insert( layer.play_cardbk); sceneGroup.play_cardbk = layer.play_cardbk 
    
        -- play_t2bg positioning 
           layer.play_t2bg = display.newImageRect( composer.imgDir.. "p2_play_t2bg.png", 1044, 156 ); 
           layer.play_t2bg.x = 780; layer.play_t2bg.y = 1079; layer.play_t2bg.alpha = 1; layer.play_t2bg.oldAlpha = 1 
           layer.play_t2bg.oriX = layer.play_t2bg.x; layer.play_t2bg.oriY = layer.play_t2bg.y 
           layer.play_t2bg.oriXs = layer.play_t2bg.xScale; layer.play_t2bg.oriYs = layer.play_t2bg.yScale 
           layer.play_t2bg.name = "play_t2bg" 
           sceneGroup:insert( layer.play_t2bg); sceneGroup.play_t2bg = layer.play_t2bg 
    
        -- play_t2minus positioning 
           layer.play_t2minus = display.newImageRect( composer.imgDir.. "p2_play_t2minus.png", 110, 110 ); 
           layer.play_t2minus.x = 1191; layer.play_t2minus.y = 1074; layer.play_t2minus.alpha = 1; layer.play_t2minus.oldAlpha = 1 
           layer.play_t2minus.oriX = layer.play_t2minus.x; layer.play_t2minus.oriY = layer.play_t2minus.y 
           layer.play_t2minus.oriXs = layer.play_t2minus.xScale; layer.play_t2minus.oriYs = layer.play_t2minus.yScale 
           layer.play_t2minus.name = "play_t2minus" 
           sceneGroup:insert( layer.play_t2minus); sceneGroup.play_t2minus = layer.play_t2minus 
    
        -- play_t2plus positioning 
           layer.play_t2plus = display.newImageRect( composer.imgDir.. "p2_play_t2plus.png", 110, 110 ); 
           layer.play_t2plus.x = 1054; layer.play_t2plus.y = 1074; layer.play_t2plus.alpha = 1; layer.play_t2plus.oldAlpha = 1 
           layer.play_t2plus.oriX = layer.play_t2plus.x; layer.play_t2plus.oriY = layer.play_t2plus.y 
           layer.play_t2plus.oriXs = layer.play_t2plus.xScale; layer.play_t2plus.oriYs = layer.play_t2plus.yScale 
           layer.play_t2plus.name = "play_t2plus" 
           sceneGroup:insert( layer.play_t2plus); sceneGroup.play_t2plus = layer.play_t2plus 
    
        -- play_t1bg positioning 
           layer.play_t1bg = display.newImageRect( composer.imgDir.. "p2_play_t1bg.png", 1044, 156 ); 
           layer.play_t1bg.x = 780; layer.play_t1bg.y = 915; layer.play_t1bg.alpha = 1; layer.play_t1bg.oldAlpha = 1 
           layer.play_t1bg.oriX = layer.play_t1bg.x; layer.play_t1bg.oriY = layer.play_t1bg.y 
           layer.play_t1bg.oriXs = layer.play_t1bg.xScale; layer.play_t1bg.oriYs = layer.play_t1bg.yScale 
           layer.play_t1bg.name = "play_t1bg" 
           sceneGroup:insert( layer.play_t1bg); sceneGroup.play_t1bg = layer.play_t1bg 
    
        -- play_t1minus positioning 
           layer.play_t1minus = display.newImageRect( composer.imgDir.. "p2_play_t1minus.png", 110, 110 ); 
           layer.play_t1minus.x = 1191; layer.play_t1minus.y = 910; layer.play_t1minus.alpha = 1; layer.play_t1minus.oldAlpha = 1 
           layer.play_t1minus.oriX = layer.play_t1minus.x; layer.play_t1minus.oriY = layer.play_t1minus.y 
           layer.play_t1minus.oriXs = layer.play_t1minus.xScale; layer.play_t1minus.oriYs = layer.play_t1minus.yScale 
           layer.play_t1minus.name = "play_t1minus" 
           sceneGroup:insert( layer.play_t1minus); sceneGroup.play_t1minus = layer.play_t1minus 
    
        -- play_t1plus positioning 
           layer.play_t1plus = display.newImageRect( composer.imgDir.. "p2_play_t1plus.png", 110, 110 ); 
           layer.play_t1plus.x = 1054; layer.play_t1plus.y = 910; layer.play_t1plus.alpha = 1; layer.play_t1plus.oldAlpha = 1 
           layer.play_t1plus.oriX = layer.play_t1plus.x; layer.play_t1plus.oriY = layer.play_t1plus.y 
           layer.play_t1plus.oriXs = layer.play_t1plus.xScale; layer.play_t1plus.oriYs = layer.play_t1plus.yScale 
           layer.play_t1plus.name = "play_t1plus" 
           sceneGroup:insert( layer.play_t1plus); sceneGroup.play_t1plus = layer.play_t1plus 
    
        -- play_howto positioning 
           layer.play_howto = display.newImageRect( composer.imgDir.. "p2_play_howto.png", 320, 158 ); 
           layer.play_howto.x = 392; layer.play_howto.y = 1555; layer.play_howto.alpha = 1; layer.play_howto.oldAlpha = 1 
           layer.play_howto.oriX = layer.play_howto.x; layer.play_howto.oriY = layer.play_howto.y 
           layer.play_howto.oriXs = layer.play_howto.xScale; layer.play_howto.oriYs = layer.play_howto.yScale 
           layer.play_howto.name = "play_howto" 
           sceneGroup:insert( layer.play_howto); sceneGroup.play_howto = layer.play_howto 
    
        -- play_newgame positioning 
           layer.play_newgame = display.newImageRect( composer.imgDir.. "p2_play_newgame.png", 326, 166 ); 
           layer.play_newgame.x = 770; layer.play_newgame.y = 1555; layer.play_newgame.alpha = 1; layer.play_newgame.oldAlpha = 1 
           layer.play_newgame.oriX = layer.play_newgame.x; layer.play_newgame.oriY = layer.play_newgame.y 
           layer.play_newgame.oriXs = layer.play_newgame.xScale; layer.play_newgame.oriYs = layer.play_newgame.yScale 
           layer.play_newgame.name = "play_newgame" 
           sceneGroup:insert( layer.play_newgame); sceneGroup.play_newgame = layer.play_newgame 
    
        -- play_rules positioning 
           layer.play_rules = display.newImageRect( composer.imgDir.. "p2_play_rules.png", 326, 166 ); 
           layer.play_rules.x = 1150; layer.play_rules.y = 1556; layer.play_rules.alpha = 1; layer.play_rules.oldAlpha = 1 
           layer.play_rules.oriX = layer.play_rules.x; layer.play_rules.oriY = layer.play_rules.y 
           layer.play_rules.oriXs = layer.play_rules.xScale; layer.play_rules.oriYs = layer.play_rules.yScale 
           layer.play_rules.name = "play_rules" 
           sceneGroup:insert( layer.play_rules); sceneGroup.play_rules = layer.play_rules 
    
        -- tm1scoretxt positioning 
           layer.tm1scoretxt = display.newImageRect( composer.imgDir.. "p2_tm1scoretxt.png", 29, 43 ); 
           layer.tm1scoretxt.x = 916; layer.tm1scoretxt.y = 911; layer.tm1scoretxt.alpha = 1; layer.tm1scoretxt.oldAlpha = 1 
           layer.tm1scoretxt.oriX = layer.tm1scoretxt.x; layer.tm1scoretxt.oriY = layer.tm1scoretxt.y 
           layer.tm1scoretxt.oriXs = layer.tm1scoretxt.xScale; layer.tm1scoretxt.oriYs = layer.tm1scoretxt.yScale 
           layer.tm1scoretxt.name = "tm1scoretxt" 
           sceneGroup:insert( layer.tm1scoretxt); sceneGroup.tm1scoretxt = layer.tm1scoretxt 
    
        -- tm2scoretxt positioning 
           layer.tm2scoretxt = display.newImageRect( composer.imgDir.. "p2_tm2scoretxt.png", 29, 43 ); 
           layer.tm2scoretxt.x = 916; layer.tm2scoretxt.y = 1075; layer.tm2scoretxt.alpha = 1; layer.tm2scoretxt.oldAlpha = 1 
           layer.tm2scoretxt.oriX = layer.tm2scoretxt.x; layer.tm2scoretxt.oriY = layer.tm2scoretxt.y 
           layer.tm2scoretxt.oriXs = layer.tm2scoretxt.xScale; layer.tm2scoretxt.oriYs = layer.tm2scoretxt.yScale 
           layer.tm2scoretxt.name = "tm2scoretxt" 
           sceneGroup:insert( layer.tm2scoretxt); sceneGroup.tm2scoretxt = layer.tm2scoretxt 
    
        -- tm1box positioning 
           layer.tm1box = native.newTextField( 584, 895, 553, 39 ) 
           layer.tm1box.input = "default" 
           layer.tm1box.anchorX = 0.5; layer.tm1box.anchorY = 0; 
           repositionAnchor(layer.tm1box,0.5,0); 
           layer.tm1box.oriX = layer.tm1box.x; layer.tm1box.oriY = layer.tm1box.y 
           layer.tm1box.oriXs = layer.tm1box.xScale; layer.tm1box.oriYs = layer.tm1box.yScale 
           sceneGroup:insert( layer.tm1box); sceneGroup.tm1box = layer.tm1box 
     
           -- Group(s) creation 
    
           -- AFTER variables 
    
           -- (MIDDLE) External code will render here 
    
           -- Repositions according anchor points 
    
    end -- ends scene:create
    
    -- Called when the scene's view is about to 'will/load' or 'did/appear': 
    function scene:show( event ) 
       local sceneGroup = self.view 
    
       if event.phase == "did" then 
          -- purges previous and next scenes 
          local __prevScene = composer.getSceneName( "previous" ) 
          if nil~= __prevScene then composer.removeScene(__prevScene, true) end   
    
          -- Check for previous bookmarks 
           if (tonumber(composer.kBookmark) == 1) then 
              local path = system.pathForFile( "book.txt", system.DocumentsDirectory ) 
              local file = io.open( path, "w+" ) 
              file:write ( curPage.."\n1" ) 
              io.close( file ) 
           end 
    
          -- Check for for auto play settings 
           if (tonumber(composer.kAutoPlay) > 0) then 
             local function act_autoPlay(event) 
               if(curPage < numPages) then 
                  if nil~= composer.getScene( "page_"..curPage+1) then composer.removeScene( "page_"..curPage+1, true) end 
                  if(composer.kBidi == false) then  
                    composer.gotoScene( "page_"..curPage+1, { effect = "fromRight"} ) 
                  else  
                    composer.gotoScene( "page_"..curPage-1, { effect = "fromLeft"} ) 
                  end  
               end 
             end 
             if (tonumber(allAudios.kAutoPlay) > composer.kAutoPlay) then 
                 composer.timerStash.timer_AP = timer.performWithDelay( allAudios.kAutoPlay*1000, act_autoPlay, 1 ) 
             else  
                 composer.timerStash.timer_AP = timer.performWithDelay( composer.kAutoPlay*1000, act_autoPlay, 1 ) 
             end 
           end 
    
            local function fieldHandler_tm1box(event) 
                   if ("began" == event.phase) then  
                   elseif ("ended" == event.phase) then  
                   elseif ("submitted" == event.phase) then  
                      team1input = layer.tm1box.text 
                      native.setKeyboardFocus(nil) 
                   end  
           end 
           layer.tm1box:addEventListener( "userInput", fieldHandler_tm1box ) 
    
           -- Button event listeners 
    
           local function onkwkhomeEvent(event) 
              but_gohome(layer.kwkhome) 
              return true 
           end 
           layer.kwkhome:addEventListener("tap", onkwkhomeEvent ) 
    
           -- Button functions 
           function but_gohome(self) 
                local myClosure_switch80 = function() 
                    local options = { effect = "slideRight" } 
                    if nil~= composer.getScene("page_1") then composer.removeScene("page_1", true) end  
                    if  self.type == "press" then 
                        self:setEnabled(false) 
                    else 
                        self:removeEventListener( "tap", onkwkhomeEvent ) 
                    end 
                    composer.gotoScene( "page_1", options ) 
                end 
                composer.timerStash.newTimer_780 = timer.performWithDelay(0, myClosure_switch80, 1) 
           end 
    
           -- do not swipe this page 
    
           -- (BOTTOM) External code will render here 
           team1input = kwkVarCheck("team1input")
    layer.tm1box.text = team1input
    layer.tm1box.hasBackground = false
    layer.tm1box.anchorY = 0  
    layer.tm1box.size = 50
    layer.tm1box:setTextColor(1,1,1)
     
       end --ends phase did 
    
    end -- ends scene:show
    
    function scene:hide( event ) 
          -- purges previous and next scenes 
       -- all disposal happens here 
       if event.phase == "will" then 
         composer.reloadCanvas = 0 
         if lineTable then 
            for i=1, #lineTable do 
               lineTable[i]:removeSelf(); lineTable[i] = nil 
            end 
         end 
    
              composer.cancelAllTimers(); 
           saveKwikVars({"team1input",team1input}) 
           layer.tm1box:removeSelf(); layer.tm1box = nil 
       elseif event.phase == "did" then 
              composer.test = nil 
       end 
    end  
    
    function scene:destroy( event ) 
       -- Remove all unecessary composer items 
    end 
    
    scene:addEventListener( "create", scene ) 
    scene:addEventListener( "show", scene ) 
    scene:addEventListener( "hide", scene ) 
    scene:addEventListener( "destroy", scene ) 
    return scene 
    

    Thanks so much for your help!
    Christi

    Yamamoto
    Keymaster
    #83969

    the codes look good. I don’t see why it fails.

    >I see the – saveKwikVars({“team1input”,team1input}) – in my code but it does not show up until the scene:hide section.

    that’s correct. when the scene transition occurs, it saves the variable. It does not need to save it while fieldHandler_tm1box()

    Here is the sample of kwik project. It is working. If this does not work, please send me your kwik project file.
    http://kwiksher.com/tutorials/Keyboard/TextInputPatch.zip

    #84009

    Hi Yamamoto,
    The code to save the variable is working!! Yeah 🙂 It just doesn’t work in the corona simulator. It only works if I do a build in the iOS simulator or on the device. Thank you for that!

    My second question in regards to the replacement is how to have the text input replacement layer actually replace text or a png of text.

    What I want is for the page to initially load with the words “ENTER TEAM 1 NAME”
    When the user taps on “ENTER TEAM 1 NAME” the keyboard pops up and “ENTER TEAM 1 NAME” is replaced with what they type in the keyboard.

    I have tried a variety of different ways to make this happen and none of them seem to work. When using the text input replacement function it automatically populates the layer you are replacing with a white box and brings that layer to the front.

    See below for my current code. In this iteration, I was trying to bring the layer that says “ENTER TEAM 1 NAME” to the front if the variable for text input replacement was still nil but this doesn’t work. Please let me know if you have any other suggestions. Thank you!! Christi

    -- Code created by Kwik - Copyright: kwiksher.com 
    -- Version: 3.5.2 
    -- Project: CharadesV2, published on Sat Jul 11 2015 14:23:53 GMT-0400 
    local composer = require( "composer" ) 
    local scene = composer.newScene() 
    
    -- External libraries 
    
    -- Initial settings and checkings 
    local numPages = 2 -- number of pages in the project 
    local sceneGroup = nil -- main group for all page elements
    local W = display.contentWidth; -- full width of the page
    local H = display.contentHeight; -- full height of the page
    
         
    local curPage = 2 -- number of the current page 
    
    -- Button names 
    local but_gohome
    
    -- Variables names 
    local team1input = "TEAM 1 NAME" --  
    math.randomseed(os.time()) 
    
    -- All layers on a table 
    local layer = {} 
    
    -- All audio files on a table 
    local allAudios = {} 
    allAudios.kAutoPlay = composer.kAutoPlay 
    
    -- Calculates anchor points 
    local function repositionAnchor( object, newAnchorX, newAnchorY ) 
         local origX = object.x; local origY = object.y 
         if newAnchorX ~= 0.5 or newAnchorY ~= 0.5 then 
             local width = object.width; local height = object.height 
             local xCoord = width * (newAnchorX - .5)  
             local yCoord = height * (newAnchorY - .5) 
             object.x = origX + xCoord; object.y = origY + yCoord 
             object.oriX = object.x; object.oriY = object.y   
         end 
    end 
    
    -- Called when the scene's view does not exist:  
    function scene:create( event )  
        -- view is not yet visible  
        local sceneGroup = self.view  
        
        -- BEFORE variables 
        team1input = "TEAM 1 NAME" --  
           -- Check if variable has a pre-saved content 
           if kwkVarCheck("team1input") ~= nil then  
            team1input = kwkVarCheck("team1input") 
           end  
    
        -- Capture and set group position 
        local function groupPos(obj) 
           local minX, minY 
           for i = 1, obj.numChildren do 
              local currentRecord = obj[ i ] 
              if i == 1 then 
                 minX = currentRecord.x - currentRecord.contentWidth * 0.5 
                 minY = currentRecord.y - currentRecord.contentHeight * 0.5 
              end 
              local mX = currentRecord.x - currentRecord.contentWidth * 0.5 
              if mX < minX then 
                 minX = mX 
              end 
              local mY = currentRecord.y - currentRecord.contentHeight * 0.5 
              if mY < minY then 
                 minY = mY 
              end 
           end 
           obj.x = minX + obj.contentWidth * 0.5 
           obj.y = minY + obj.contentHeight * 0.5 
        end 
    
        -- Multilingual items 
    
        -- (TOP) External code will render here 
    
        -- kwkplay_bg positioning 
           layer.kwkplay_bg = display.newImageRect( composer.imgDir.. "kwkplay_bg.png", 1536, 2048 ); 
           layer.kwkplay_bg.x = 768; layer.kwkplay_bg.y = 1024; layer.kwkplay_bg.alpha = 1; layer.kwkplay_bg.oldAlpha = 1 
           layer.kwkplay_bg.oriX = layer.kwkplay_bg.x; layer.kwkplay_bg.oriY = layer.kwkplay_bg.y 
           layer.kwkplay_bg.oriXs = layer.kwkplay_bg.xScale; layer.kwkplay_bg.oriYs = layer.kwkplay_bg.yScale 
           layer.kwkplay_bg.name = "kwkplay_bg" 
           sceneGroup:insert( 1, layer.kwkplay_bg); sceneGroup.kwkplay_bg = layer.kwkplay_bg 
    
        -- kwkabout positioning 
           layer.kwkabout = display.newImageRect( composer.imgDir.. "kwkabout.png", 250, 250 ); 
           layer.kwkabout.x = 1198; layer.kwkabout.y = 1839; layer.kwkabout.alpha = 1; layer.kwkabout.oldAlpha = 1 
           layer.kwkabout.oriX = layer.kwkabout.x; layer.kwkabout.oriY = layer.kwkabout.y 
           layer.kwkabout.oriXs = layer.kwkabout.xScale; layer.kwkabout.oriYs = layer.kwkabout.yScale 
           layer.kwkabout.name = "kwkabout" 
           sceneGroup:insert( layer.kwkabout); sceneGroup.kwkabout = layer.kwkabout 
    
        -- kwksettings positioning 
           layer.kwksettings = display.newImageRect( composer.imgDir.. "kwksettings.png", 250, 250 ); 
           layer.kwksettings.x = 915; layer.kwksettings.y = 1839; layer.kwksettings.alpha = 1; layer.kwksettings.oldAlpha = 1 
           layer.kwksettings.oriX = layer.kwksettings.x; layer.kwksettings.oriY = layer.kwksettings.y 
           layer.kwksettings.oriXs = layer.kwksettings.xScale; layer.kwksettings.oriYs = layer.kwksettings.yScale 
           layer.kwksettings.name = "kwksettings" 
           sceneGroup:insert( layer.kwksettings); sceneGroup.kwksettings = layer.kwksettings 
    
        -- kwkplay positioning 
           layer.kwkplay = display.newImageRect( composer.imgDir.. "kwkplay.png", 250, 250 ); 
           layer.kwkplay.x = 632; layer.kwkplay.y = 1839; layer.kwkplay.alpha = 1; layer.kwkplay.oldAlpha = 1 
           layer.kwkplay.oriX = layer.kwkplay.x; layer.kwkplay.oriY = layer.kwkplay.y 
           layer.kwkplay.oriXs = layer.kwkplay.xScale; layer.kwkplay.oriYs = layer.kwkplay.yScale 
           layer.kwkplay.name = "kwkplay" 
           sceneGroup:insert( layer.kwkplay); sceneGroup.kwkplay = layer.kwkplay 
    
        -- kwkhome positioning 
           layer.kwkhome = display.newImageRect( composer.imgDir.. "kwkhome.png", 250, 250 ); 
           layer.kwkhome.x = 349; layer.kwkhome.y = 1839; layer.kwkhome.alpha = 1; layer.kwkhome.oldAlpha = 1 
           layer.kwkhome.oriX = layer.kwkhome.x; layer.kwkhome.oriY = layer.kwkhome.y 
           layer.kwkhome.oriXs = layer.kwkhome.xScale; layer.kwkhome.oriYs = layer.kwkhome.yScale 
           layer.kwkhome.name = "kwkhome" 
           sceneGroup:insert(layer.kwkhome); sceneGroup.kwkhome = layer.kwkhome 
    
        -- play_gobtn positioning 
           layer.play_gobtn = display.newImageRect( composer.imgDir.. "p2_play_gobtn.png", 902, 222 ); 
           layer.play_gobtn.x = 768; layer.play_gobtn.y = 1307; layer.play_gobtn.alpha = 1; layer.play_gobtn.oldAlpha = 1 
           layer.play_gobtn.oriX = layer.play_gobtn.x; layer.play_gobtn.oriY = layer.play_gobtn.y 
           layer.play_gobtn.oriXs = layer.play_gobtn.xScale; layer.play_gobtn.oriYs = layer.play_gobtn.yScale 
           layer.play_gobtn.name = "play_gobtn" 
           sceneGroup:insert( layer.play_gobtn); sceneGroup.play_gobtn = layer.play_gobtn 
    
        -- play_cardbk positioning 
           layer.play_cardbk = display.newImageRect( composer.imgDir.. "p2_play_cardbk.png", 962, 692 ); 
           layer.play_cardbk.x = 769; layer.play_cardbk.y = 475; layer.play_cardbk.alpha = 1; layer.play_cardbk.oldAlpha = 1 
           layer.play_cardbk.oriX = layer.play_cardbk.x; layer.play_cardbk.oriY = layer.play_cardbk.y 
           layer.play_cardbk.oriXs = layer.play_cardbk.xScale; layer.play_cardbk.oriYs = layer.play_cardbk.yScale 
           layer.play_cardbk.name = "play_cardbk" 
           sceneGroup:insert( layer.play_cardbk); sceneGroup.play_cardbk = layer.play_cardbk 
    
        -- play_t2bg positioning 
           layer.play_t2bg = display.newImageRect( composer.imgDir.. "p2_play_t2bg.png", 1044, 156 ); 
           layer.play_t2bg.x = 780; layer.play_t2bg.y = 1079; layer.play_t2bg.alpha = 1; layer.play_t2bg.oldAlpha = 1 
           layer.play_t2bg.oriX = layer.play_t2bg.x; layer.play_t2bg.oriY = layer.play_t2bg.y 
           layer.play_t2bg.oriXs = layer.play_t2bg.xScale; layer.play_t2bg.oriYs = layer.play_t2bg.yScale 
           layer.play_t2bg.name = "play_t2bg" 
           sceneGroup:insert( layer.play_t2bg); sceneGroup.play_t2bg = layer.play_t2bg 
    
        -- play_t2minus positioning 
           layer.play_t2minus = display.newImageRect( composer.imgDir.. "p2_play_t2minus.png", 110, 110 ); 
           layer.play_t2minus.x = 1191; layer.play_t2minus.y = 1074; layer.play_t2minus.alpha = 1; layer.play_t2minus.oldAlpha = 1 
           layer.play_t2minus.oriX = layer.play_t2minus.x; layer.play_t2minus.oriY = layer.play_t2minus.y 
           layer.play_t2minus.oriXs = layer.play_t2minus.xScale; layer.play_t2minus.oriYs = layer.play_t2minus.yScale 
           layer.play_t2minus.name = "play_t2minus" 
           sceneGroup:insert( layer.play_t2minus); sceneGroup.play_t2minus = layer.play_t2minus 
    
        -- play_t2plus positioning 
           layer.play_t2plus = display.newImageRect( composer.imgDir.. "p2_play_t2plus.png", 110, 110 ); 
           layer.play_t2plus.x = 1054; layer.play_t2plus.y = 1074; layer.play_t2plus.alpha = 1; layer.play_t2plus.oldAlpha = 1 
           layer.play_t2plus.oriX = layer.play_t2plus.x; layer.play_t2plus.oriY = layer.play_t2plus.y 
           layer.play_t2plus.oriXs = layer.play_t2plus.xScale; layer.play_t2plus.oriYs = layer.play_t2plus.yScale 
           layer.play_t2plus.name = "play_t2plus" 
           sceneGroup:insert( layer.play_t2plus); sceneGroup.play_t2plus = layer.play_t2plus 
    
        -- play_tm1bg positioning 
           layer.play_tm1bg = display.newImageRect( composer.imgDir.. "p2_play_tm1bg.png", 1044, 156 ); 
           layer.play_tm1bg.x = 781; layer.play_tm1bg.y = 916; layer.play_tm1bg.alpha = 1; layer.play_tm1bg.oldAlpha = 1 
           layer.play_tm1bg.oriX = layer.play_tm1bg.x; layer.play_tm1bg.oriY = layer.play_tm1bg.y 
           layer.play_tm1bg.oriXs = layer.play_tm1bg.xScale; layer.play_tm1bg.oriYs = layer.play_tm1bg.yScale 
           layer.play_tm1bg.name = "play_tm1bg" 
           sceneGroup:insert( layer.play_tm1bg); sceneGroup.play_tm1bg = layer.play_tm1bg 
    
        -- play_t1minus positioning 
           layer.play_t1minus = display.newImageRect( composer.imgDir.. "p2_play_t1minus.png", 110, 110 ); 
           layer.play_t1minus.x = 1191; layer.play_t1minus.y = 910; layer.play_t1minus.alpha = 1; layer.play_t1minus.oldAlpha = 1 
           layer.play_t1minus.oriX = layer.play_t1minus.x; layer.play_t1minus.oriY = layer.play_t1minus.y 
           layer.play_t1minus.oriXs = layer.play_t1minus.xScale; layer.play_t1minus.oriYs = layer.play_t1minus.yScale 
           layer.play_t1minus.name = "play_t1minus" 
           sceneGroup:insert( layer.play_t1minus); sceneGroup.play_t1minus = layer.play_t1minus 
    
        -- play_t1plus positioning 
           layer.play_t1plus = display.newImageRect( composer.imgDir.. "p2_play_t1plus.png", 110, 110 ); 
           layer.play_t1plus.x = 1054; layer.play_t1plus.y = 910; layer.play_t1plus.alpha = 1; layer.play_t1plus.oldAlpha = 1 
           layer.play_t1plus.oriX = layer.play_t1plus.x; layer.play_t1plus.oriY = layer.play_t1plus.y 
           layer.play_t1plus.oriXs = layer.play_t1plus.xScale; layer.play_t1plus.oriYs = layer.play_t1plus.yScale 
           layer.play_t1plus.name = "play_t1plus" 
           sceneGroup:insert( layer.play_t1plus); sceneGroup.play_t1plus = layer.play_t1plus 
    
        -- play_howto positioning 
           layer.play_howto = display.newImageRect( composer.imgDir.. "p2_play_howto.png", 320, 158 ); 
           layer.play_howto.x = 392; layer.play_howto.y = 1555; layer.play_howto.alpha = 1; layer.play_howto.oldAlpha = 1 
           layer.play_howto.oriX = layer.play_howto.x; layer.play_howto.oriY = layer.play_howto.y 
           layer.play_howto.oriXs = layer.play_howto.xScale; layer.play_howto.oriYs = layer.play_howto.yScale 
           layer.play_howto.name = "play_howto" 
           sceneGroup:insert( layer.play_howto); sceneGroup.play_howto = layer.play_howto 
    
        -- play_newgame positioning 
           layer.play_newgame = display.newImageRect( composer.imgDir.. "p2_play_newgame.png", 326, 166 ); 
           layer.play_newgame.x = 770; layer.play_newgame.y = 1555; layer.play_newgame.alpha = 1; layer.play_newgame.oldAlpha = 1 
           layer.play_newgame.oriX = layer.play_newgame.x; layer.play_newgame.oriY = layer.play_newgame.y 
           layer.play_newgame.oriXs = layer.play_newgame.xScale; layer.play_newgame.oriYs = layer.play_newgame.yScale 
           layer.play_newgame.name = "play_newgame" 
           sceneGroup:insert( layer.play_newgame); sceneGroup.play_newgame = layer.play_newgame 
    
        -- play_rules positioning 
           layer.play_rules = display.newImageRect( composer.imgDir.. "p2_play_rules.png", 326, 166 ); 
           layer.play_rules.x = 1150; layer.play_rules.y = 1556; layer.play_rules.alpha = 1; layer.play_rules.oldAlpha = 1 
           layer.play_rules.oriX = layer.play_rules.x; layer.play_rules.oriY = layer.play_rules.y 
           layer.play_rules.oriXs = layer.play_rules.xScale; layer.play_rules.oriYs = layer.play_rules.yScale 
           layer.play_rules.name = "play_rules" 
           sceneGroup:insert( layer.play_rules); sceneGroup.play_rules = layer.play_rules 
    
        -- tm1scoretxt positioning 
           layer.tm1scoretxt = display.newImageRect( composer.imgDir.. "p2_tm1scoretxt.png", 29, 43 ); 
           layer.tm1scoretxt.x = 916; layer.tm1scoretxt.y = 911; layer.tm1scoretxt.alpha = 1; layer.tm1scoretxt.oldAlpha = 1 
           layer.tm1scoretxt.oriX = layer.tm1scoretxt.x; layer.tm1scoretxt.oriY = layer.tm1scoretxt.y 
           layer.tm1scoretxt.oriXs = layer.tm1scoretxt.xScale; layer.tm1scoretxt.oriYs = layer.tm1scoretxt.yScale 
           layer.tm1scoretxt.name = "tm1scoretxt" 
           sceneGroup:insert( layer.tm1scoretxt); sceneGroup.tm1scoretxt = layer.tm1scoretxt 
    
        -- tm2scoretxt positioning 
           layer.tm2scoretxt = display.newImageRect( composer.imgDir.. "p2_tm2scoretxt.png", 29, 43 ); 
           layer.tm2scoretxt.x = 916; layer.tm2scoretxt.y = 1075; layer.tm2scoretxt.alpha = 1; layer.tm2scoretxt.oldAlpha = 1 
           layer.tm2scoretxt.oriX = layer.tm2scoretxt.x; layer.tm2scoretxt.oriY = layer.tm2scoretxt.y 
           layer.tm2scoretxt.oriXs = layer.tm2scoretxt.xScale; layer.tm2scoretxt.oriYs = layer.tm2scoretxt.yScale 
           layer.tm2scoretxt.name = "tm2scoretxt" 
           sceneGroup:insert( layer.tm2scoretxt); sceneGroup.tm2scoretxt = layer.tm2scoretxt 
    
        -- entertm1txt positioning 
           layer.entertm1txt = display.newImageRect( composer.imgDir.. "p2_entertm1txt.png", 546, 40 ); 
           layer.entertm1txt.x = 583; layer.entertm1txt.y = 913; layer.entertm1txt.alpha = 1; layer.entertm1txt.oldAlpha = 1 
           layer.entertm1txt.oriX = layer.entertm1txt.x; layer.entertm1txt.oriY = layer.entertm1txt.y 
           layer.entertm1txt.oriXs = layer.entertm1txt.xScale; layer.entertm1txt.oriYs = layer.entertm1txt.yScale 
           layer.entertm1txt.name = "entertm1txt" 
           sceneGroup:insert( layer.entertm1txt); sceneGroup.entertm1txt = layer.entertm1txt 
    
        -- entertm2txt positioning 
           layer.entertm2txt = display.newImageRect( composer.imgDir.. "p2_entertm2txt.png", 553, 39 ); 
           layer.entertm2txt.x = 586; layer.entertm2txt.y = 1073; layer.entertm2txt.alpha = 1; layer.entertm2txt.oldAlpha = 1 
           layer.entertm2txt.oriX = layer.entertm2txt.x; layer.entertm2txt.oriY = layer.entertm2txt.y 
           layer.entertm2txt.oriXs = layer.entertm2txt.xScale; layer.entertm2txt.oriYs = layer.entertm2txt.yScale 
           layer.entertm2txt.name = "entertm2txt" 
           sceneGroup:insert( layer.entertm2txt); sceneGroup.entertm2txt = layer.entertm2txt 
    
        -- tm1box positioning 
           layer.tm1box = native.newTextField( 583, 853, 629, 116 ) 
           layer.tm1box.input = "default" 
           layer.tm1box.anchorX = 0.5; layer.tm1box.anchorY = 0; 
           repositionAnchor(layer.tm1box,0.5,0); 
           layer.tm1box.oriX = layer.tm1box.x; layer.tm1box.oriY = layer.tm1box.y 
           layer.tm1box.oriXs = layer.tm1box.xScale; layer.tm1box.oriYs = layer.tm1box.yScale 
           sceneGroup:insert( layer.tm1box); sceneGroup.tm1box = layer.tm1box 
     
           -- Group(s) creation 
    
           -- AFTER variables 
    
           -- (MIDDLE) External code will render here 
           -- ATTEMPTING TO BRING THE LAYER THAT SAYS "ENTER TEAM 1 NAME" TO THE FRONT IF THE USER HAS YET TO ENTER IN A NAME VIA THE KEYBOARD.
           if team1input == "TEAM 1 NAME" then 
    	layer.entertm1txt:toFront()
    else
    	layer.entertm1txt.alpha = 0
    end 
    
           -- Repositions according anchor points 
    
    end -- ends scene:create
    
    -- Called when the scene's view is about to 'will/load' or 'did/appear': 
    function scene:show( event ) 
       local sceneGroup = self.view 
    
       if event.phase == "did" then 
          -- purges previous and next scenes 
          local __prevScene = composer.getSceneName( "previous" ) 
          if nil~= __prevScene then composer.removeScene(__prevScene, true) end   
    
          -- Check for previous bookmarks 
           if (tonumber(composer.kBookmark) == 1) then 
              local path = system.pathForFile( "book.txt", system.DocumentsDirectory ) 
              local file = io.open( path, "w+" ) 
              file:write ( curPage.."\n1" ) 
              io.close( file ) 
           end 
    
          -- Check for for auto play settings 
           if (tonumber(composer.kAutoPlay) > 0) then 
             local function act_autoPlay(event) 
               if(curPage < numPages) then 
                  if nil~= composer.getScene( "page_"..curPage+1) then composer.removeScene( "page_"..curPage+1, true) end 
                  if(composer.kBidi == false) then  
                    composer.gotoScene( "page_"..curPage+1, { effect = "fromRight"} ) 
                  else  
                    composer.gotoScene( "page_"..curPage-1, { effect = "fromLeft"} ) 
                  end  
               end 
             end 
             if (tonumber(allAudios.kAutoPlay) > composer.kAutoPlay) then 
                 composer.timerStash.timer_AP = timer.performWithDelay( allAudios.kAutoPlay*1000, act_autoPlay, 1 ) 
             else  
                 composer.timerStash.timer_AP = timer.performWithDelay( composer.kAutoPlay*1000, act_autoPlay, 1 ) 
             end 
           end 
    
            local function fieldHandler_tm1box(event) 
                   if ("began" == event.phase) then  
                   elseif ("ended" == event.phase) then  
                   elseif ("submitted" == event.phase) then  
                      team1input = layer.tm1box.text 
                      native.setKeyboardFocus(nil) 
                   end  
           end 
           layer.tm1box:addEventListener( "userInput", fieldHandler_tm1box ) 
    
           -- Button event listeners 
    
           local function onkwkhomeEvent(event) 
              but_gohome(layer.kwkhome) 
              return true 
           end 
           layer.kwkhome:addEventListener("tap", onkwkhomeEvent ) 
    
           -- Button functions 
           function but_gohome(self) 
                local myClosure_switch89 = function() 
                    local options = { effect = "slideRight" } 
                    if nil~= composer.getScene("page_1") then composer.removeScene("page_1", true) end  
                    if  self.type == "press" then 
                        self:setEnabled(false) 
                    else 
                        self:removeEventListener( "tap", onkwkhomeEvent ) 
                    end 
                    composer.gotoScene( "page_1", options ) 
                end 
                composer.timerStash.newTimer_189 = timer.performWithDelay(0, myClosure_switch89, 1) 
           end 
    
           -- do not swipe this page 
    
           -- (BOTTOM) External code will render here 
           team1input = kwkVarCheck("team1input")
    layer.tm1box.text = team1input
    --layer.tm1box.hasBackground = false
    --layer.tm1box.size = 70
    --layer.tm1box:setTextColor( 1, 1, 1)
    layer.tm1box.y = layer.tm1box.y + (layer.tm1box.height * .5) 
       end --ends phase did 
    
    end -- ends scene:show
    
    function scene:hide( event ) 
          -- purges previous and next scenes 
       -- all disposal happens here 
       if event.phase == "will" then 
         composer.reloadCanvas = 0 
         if lineTable then 
            for i=1, #lineTable do 
               lineTable[i]:removeSelf(); lineTable[i] = nil 
            end 
         end 
    
              composer.cancelAllTimers(); 
           saveKwikVars({"team1input",team1input}) 
           layer.tm1box:removeSelf(); layer.tm1box = nil 
       elseif event.phase == "did" then 
              composer.test = nil 
       end 
    end  
    
    function scene:destroy( event ) 
       -- Remove all unecessary composer items 
    end 
    
    scene:addEventListener( "create", scene ) 
    scene:addEventListener( "show", scene ) 
    scene:addEventListener( "hide", scene ) 
    scene:addEventListener( "destroy", scene ) 
    return scene 
    
    Yamamoto
    Keymaster
    #84019

    the following ext codes should be with if condition
    ————————————————
    team1input = kwkVarCheck(“team1input”)
    layer.tm1box.text = team1input
    ————————————————

     if kwkVarCheck("team1input") ~= nil then  
       team1input = kwkVarCheck("team1input")
     end
     layer.tm1box.text = team1input
    

    Kwik3.5.3 does not have the if condition, I need to fix it too.

    #84029

    Fabulous! Solved and working with this external code at the bottom. Thank you Yamamoto!!!

    -- (BOTTOM) External code will render here 
           team1input = kwkVarCheck("team1input")
    
    if (team1input == nil) then
    	layer.tm1box.text = "ENTER TEAM 1 NAME"
    else 
    	layer.tm1box.text = team1input	
    end
    
    team2input = kwkVarCheck("team2input")
    
    if (team2input == nil) then
    	layer.tm2box.text = "ENTER TEAM 2 NAME"
    else 
    	layer.tm2box.text = team2input	
    end
    
Viewing 9 posts - 1 through 9 (of 9 total)

The forum ‘Help me!’ is closed to new topics and replies.