Hi all,
I have what I hope will be a fairly trivial problem. I have an update function that downloads data from a website and updates a database appropriately. I’d like some indication that there is activity taking place, so I thought I would simply put an “Updating” message on the screen and then change the text of the message to the name of the item that’s updating as I loop over them. On complete it would say “Update complete”. The “Updating” and “Update complete” parts are working, but it doesn’t change the text to the name of the current item. When I print the current item inside “updateMessage” it’s as I would expect it to be, and when I print “message.text” in the same location it also looks like what I’d expect i.e. "Updating ". The onscreen message doesn’t change though.
Any help would be appreciated.<br>function update()<br> <br> local background = display.newRect(0,display.screenOriginY, display.contentWidth, 900)<br> background:setFillColor(0, 0, 0)<br> background.alpha = 0.7<br> <br> local message = display.newText("Updating", 0, 0, native.systemFont, 24)<br> message.x = 100 + message.width*0.5<br> message.y = display.contentCenterY<br> <br> local function updateMessage(text)<br> message.text = text<br> print("mt:"..message.text)<br> end<br> <br> local function networkListener( event )<br> <br> local function removeMessage()<br> message:removeSelf()<br> background:removeSelf()<br> end<br> <br> if ( event.isError ) then<br> message.text = "Network error!"<br> local messageTimer = timer.performWithDelay( 1500, removeMessage )<br> else<br> local data = Json.Decode(event.response)<br> for i = 1, #data.artists do<br> local present = false<br> local id = 0<br> local dataItem = data.artists[i]<br> local sql = "select id from artists where name = '"..dataItem.name.."'"<br> <br> for row in db:nrows(sql) do<br> present = true<br> id = row.id<br> end<br> <br> <br> if(present == false) then<br> sql = [[insert into artists(name,bio,day,date,venue,time) values(']]..dataItem.name..[[',']]..dataItem.bio..[[',']]..dataItem.day..[[',']]..dataItem.date..[[',]]..dataItem.venue..[[,']]..dataItem.time..[[')]]<br> updateMessage("Adding "..dataItem.name)<br> else<br> sql = [[update artists set name = ']]..dataItem.name..[[', bio=']]..dataItem.bio..[[',day=']]..dataItem.day..[[',date=']]..dataItem.date..[[',venue=]]..dataItem.venue..[[,time=']]..dataItem.time..[[' where id =]]..id..[[]]<br> updateMessage("Updating "..dataItem.name)<br> end<br> <br> print(sql)<br> db:exec( sql )<br> <br> end<br> <br> message.text = "Update complete"<br> local loadingTimer = timer.performWithDelay( 1500, removeMessage )<br> <br> end<br> end<br> <br> -- Access Google over SSL:<br> network.request( "http://www.myurl.com/test.txt", "GET", networkListener )<br>end<br> [import]uid: 69057 topic_id: 11299 reply_id: 311299[/import]