So I have a button that when pressed runs and gets one random row from a database.
This works fine. Now, how do I get rid of the result from the display, and print a new result when the button is pressed again?
Ive tried placing display.remove in a number of places but cant quite seem to figure it out. Currently pressing the buttton just places a new result on top of the old one.
–
local function page(event)
for row in db:nrows(“SELECT name from database ORDER BY RANDOM() LIMIT 1”) do
local result = row.names
local text = display.newText(result, 50, 120, native.systemFont, 16)
text:setFillColor(1,0,1)
end
end
local button = display.newImage(“icon.png”)
button.x = 225
button.y = 250
button:addEventListener(“tap”, page)
–
Pointers to how to do this are welcome.