it’s not like that.
-- INCLUDE REQUIRED LIBRARIES
local widget = require("widget") -- for status label
local userid = nil
local password = nil
-- SET BACKGROUND
local background = display.newRect( sceneGroup, 420, 450,500, 500)
background:setFillColor(100,100,100);
-- CREATE LOGIN SCREEN
-- CREATE LABELS
local labelHeadline = display.newText( sceneGroup, " Add User setting", 0, 0, font, 57)
labelHeadline.x = 375
labelHeadline.y = 60
--loginScreen:insert(labelHeadline)
local labelUsername = display.newText( sceneGroup, " enter your username", 0, 0, font, 36)
labelUsername:setTextColor(0, 0, 0)
labelUsername.x = 410
labelUsername.y = 229
--loginScreen:insert(labelUsername)
local labelPassword = display.newText( sceneGroup, " enter your password", 0, 0, font, 35)
labelPassword:setTextColor(0, 0, 0)
labelPassword.x = 375
labelPassword.y = 470
--loginScreen:insert(labelPassword)
local labelReturnStatus = display.newText( sceneGroup , "", 0, 0, font, 47)
labelReturnStatus.x = 400
labelReturnStatus.y = 740
labelReturnStatus:setFillColor( 0, 0, 0 )
local labelReturnStatus1 = display.newText( sceneGroup , "", 0, 0, font, 35)
labelReturnStatus1.x = 400
labelReturnStatus1.y = 1000
labelReturnStatus1:setFillColor( 0, 0, 0 )
local labelReturnStatus2 = display.newText( sceneGroup , "", 0, 0, font, 35)
labelReturnStatus2.x = 400
labelReturnStatus2.y = 1040
labelReturnStatus2:setFillColor( 0, 0, 0 )
--loginScreen:insert(labelReturnStatus)
-- CREATE USERNAME TEXT FIELD - ADD TO LOGIN FORM
local frmUsernam = native.newTextField( 0, 0, 360, 100)
frmUsernam.inputType = "default"
frmUsernam.font = native.newFont(font, 50)
frmUsernam.isEditable = true
frmUsernam.align = "center"
frmUsernam.x = 415
frmUsernam.y = 335
frmUsernam.text = 'Response 1'
-- add login form field to login screen
sceneGroup:insert(frmUsernam)
-- handle field events
function frmUsernam:userInput(event)
if(event.phase == "began") then
-- you could implement tweening of object to get out of the way of the keyboard here
print("Began frmUsername" .. ' ' .. event.target.text)
event.target.text = ''
elseif(event.phase == "editing") then
-- fired with each new character
print("Editing frmUsername" .. ' ' .. event.target.text)
elseif(event.phase == "ended") then
-- fired when the field looses focus as a result of some other object being interacted with
print("Ended frmUsername" .. ' ' .. event.target.text)
elseif(event.phase == "submitted") then
-- you could implement tweening of objects to their original postion here
print("Submitted frmUsername" .. ' ' .. event.target.text)
end
end
frmUsernam:addEventListener("userInput",frmUsernam)
-- CREATE PASSWORD TEXT FIELD - ADD TO LOGIN FORM
local frmPassword = native.newTextField(0, 0, 360, 100)
frmPassword.inputType = "default"
frmPassword.font = native.newFont(font, 50)
frmPassword.isEditable = true
frmPassword.isSecure = false
frmPassword.align = "center"
frmPassword.x = 415
frmPassword.y = 565
frmPassword.text = 'Response 2'
-- add login form field to login screen
sceneGroup:insert(frmPassword)
-- handle field events
function frmPassword:userInput(event)
if(event.phase == "began") then
-- you could implement tweening of object to get out of the way of the keyboard here
print("Began Password" .. ' ' .. event.target.text)
event.target.text = ''
elseif(event.phase == "editing") then
-- fired with each new character
print("Editing Password" .. ' ' .. event.target.text)
elseif(event.phase == "ended") then
-- fired when the field looses focus as a result of some other object being interacted with
print("Ended Password" .. ' ' .. event.target.text)
elseif(event.phase == "submitted") then
-- you could implement tweening of objects to their original postion here
print("Submitted Password" .. ' ' .. event.target.text)
end
end
frmPassword:addEventListener("userInput",frmPassword)
-- MAKE KEYBOARD GO AWAY ON BACKGROUND TAP
function background:tap(event)
native.setKeyboardFocus(nil)
end
background:addEventListener("tap",background)
-- HANDLE BUTTON PRESS
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
local function btnOnPressHandler(event)
local path = system.pathForFile( "db.txt", system.DocumentsDirectory ) ----open the file path------ok
local userid = frmUsernam.text ------------------------------------------------------input text--------------ok
if(userid == '') then labelReturnStatus1.text = "invalid entry !" ---------------------------------------------ok
elseif error then
local file = io.open( path, "r" ) ----------------------------------------------------Open the file handle---------ok
for line in file:lines() do
if(line == userid ) then labelReturnStatus1.text = "already existe ! "---------------------------------------ok
elseif error then
local file = io.open( path, "w" )
file:write(userid) ----------------------------------------------------------------------------------------not works !!
--io.close( file )
--file = nil
labelReturnStatus1.text = userid---------------------------------------------------------------------------------ok
labelReturnStatus2.text = "has been added"------------------------------------------------------------------ok
end
end
end
end
--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- create button
local btn = widget.newButton({
id = "Login Button",
left = 310,
top = 770,
label ="Sign up",
defaultFile="image/button.png",
overFile ="image/boulble.png",
width = 200,
height = 100,
font = font,
fontSize = 53,
labelColor = { default = {0,0,1},
over = {255,255,255} },
defaultColor = {201,107,61},
overColor = {219,146,85},
onPress = btnOnPressHandler,
onDrag = btnOnDragHandler,
onRelease = btnOnReleaseHandler
})
-- add button to login screen
sceneGroup:insert(btn)
-- END OF LOGIN SCREEN