I have a condition that I’m checking for and what I would like to do is bring up an alert if the condition is reached. It will basically tell the player they have did something incorrect. I see the native alert instructions that they have on the site but I’m not sure how to use those in conjunction with a keyboard dismissal.
So basically what I want is when a player is finish entering the number in numberFieldEight they tap the screen to dismiss the keyboard. I then want my coding to run to check to see if the player did the entry correct and if not the alert comes up. I have my coding below but not sure how to tie the alert to the coding and where.
[lua]module(…, package.seeall)
function new()
local localGroup = display.newGroup()
–> This is how we start every single file or “screen” in our folder, except for main.lua
– and director.lua
–> director.lua is NEVER modified, while only one line in main.lua changes, described in that file
local ui = require(“ui”)
– Predefine local objects for use later
local numberFieldSeven, numberFieldEight
local fields = display.newGroup()
local inputFontSize = 30
local inputFontHeight = 30
local tHeight = 50
local screen5 = display.newImage (“screen5.png”)
localGroup:insert(screen5)
–> This sets Screen5
local smallbrain = display.newImage (“smallbrain.png”)
smallbrain.x = 270
smallbrain.y = 430
smallbrain.xScale = .5
smallbrain.yScale = .5
localGroup:insert(smallbrain)
–>This places the brain
local function touchedSmallbrain (event)
if (“ended” == event.phase) then
_G.numberEight = numberFieldEight.text
director:changeScene (“screen6”)
media.playEventSound( “click_x.caf” )
end
end
smallbrain:addEventListener (“touch”, touchedSmallbrain)
– Tapping screen dismisses the keyboard
local listener = function( event )
– Hide keyboard
print(“tap pressed”)
native.setKeyboardFocus( nil )
end
Runtime:addEventListener( “tap”, listener )
—>code to determine if numbers match
local function sortnum(number)
local numbersin = {}
local reminder
local returnnum = 0
if number ~=nil then
while number ~=0 do
reminder = number % 10
number = (number - (number % 10)) /10
table.insert(numbersin,reminder)
end
local mult = 1
table.sort(numbersin)
for i=1,#numbersin,1 do
returnnum = returnnum + (numbersin[i] * mult )
mult = mult * 10
end
end
return returnnum
end
local number1 = 2455
local number2 = 5245
if sortnum(number1) == sortnum(number2) then
print(“same”)
else
print(“not same”)
end
—> end of number match code
numberFieldSeven = native.newTextField( 50, 80, 85, tHeight, onnumberFieldSeven )
numberFieldSeven.font = native.newFont( native.systemFontBold, inputFontSize )
numberFieldSeven.inputType = “number”
numberFieldSeven.align = “center”
numberFieldSeven.text = _G.numberOne
numberFieldEight = native.newTextField( 180, 80, 85, tHeight, onnumberFieldEight )
numberFieldEight.font = native.newFont( native.systemFontBold, inputFontSize )
numberFieldEight.align = “center”
numberFieldEight.inputType = “number”
– Add fields to our new group
localGroup:insert(numberFieldSeven)
localGroup:insert(numberFieldEight)
–>MUST return a display.newGroup()
–> This is how we end every file except for director and main, as mentioned in my first comment
return localGroup
end[/lua] [import]uid: 72372 topic_id: 14056 reply_id: 314056[/import]
[import]uid: 71210 topic_id: 14056 reply_id: 51829[/import]