Hi,
I’m really, really new to Lua and Corona, so undoubtedly I’m doing something wrong and wonder if I could get some advice…
I’ve set up a pickerWheel and button to be shown on a release event and when the button is pressed it updates a text field and should remove the picker and button, but it never goes away (I’m using the simulator).
My code goes something like:
local widget = require("widget") local displayClock local displayClockAmPm local pickerSetBtn local pickerWheel local pickerData = {} local pickerHours = {} local pickerMinutes = {} local pickerAmPm = {"am", "pm"} for i = 1, 12 do pickerHours[i] = i end for i = 1, 60 do pickerMinutes[i] = string.format("%02d", i-1) end local function saveTime(hour, minute, ampm) -- set the value of displayClock and displayClockAmPm -- this bit works fine end local function setTimeValue(event) local v = pickerWheel:getValues() local h = v[1].value local m = v[2].value local a = v[3].value saveTime(h, m, a) display.remove(pickerSetBtn) pickerSetBtn = nil display.remove(pickerWheel) pickerWheel = nil end local function initPicker(event) pickerWheel = widget.newPickerWheel{ columns = { { align = "right", startIndex = settings.wakeHour, labels = pickerHours, }, { align = "center", startIndex = settings.wakeMin + 1, labels = pickerMinutes, }, { align = "center", startIndex = (settings.wakeAmPm == "am" and 1 or 2), labels = pickerAmPm, } } } pickerWheel.y = display.contentHeight - pickerWheel.height pickerSetBtn = widget.newButton{ label="Set time", onRelease=setTimeValue } pickerSetBtn:setReferencePoint(display.CenterRightReferencePoint) pickerSetBtn.x = display.contentWidth - 5 pickerSetBtn.y = 22 end local function initClock() displayClock = display.newText("", 0, 0, displayClockFont, 180) displayClockAmPm = display.newText("", 0, 0, displayClockFont, 30) displayClock:addEventListener("touch", initPicker) end initClock()
Any help/advice would be really appreciated - not only on this particular problem but also if you see anything I’m doing that’s completely bonkers.
Thanks!