I am reading data from a table and need for the player to answer a few questions via a native.showalert if a certain condition is true (id = true). See example below. My problem is that the code will loop through all 5 records and only show the alert on the last record that meets the condition (Sally Anne). I need for it to finish up the inner code before going on to the next record in the for-loop.
According to the documentation the code will continue in the background on a native.showalert so I understand why and what the code is doing so what I am really asking for are ideas on other ways around this without having to write my own version of native.showalert.
Thanks ahead of time!
Scott
local data = { {name = "Jim Smith", id = false}, {name = "Jane Doe", id = true}, {name = "John Gee", id = false}, {name = "Sally Anne", id = true}, {name = "Freddie Mac", id = false} } for j = 1, #data do print("j", j, "id", data[j].id) if data[j].id == true then local function onLevel( event ) if event.action == "clicked" then local action = event.index if action == 3 then local levelText = "Rookie" elseif action == 2 then levelText = "All-Star" end local function onComplete( event ) if event.action == "clicked" then local action2 = event.index if action2 == 1 then print("made it to inner alert") end end end native.showAlert( "Notification", "Are you sure you want to send this game request?", { "OK", "Cancel" }, onComplete ) end end native.showAlert( "Notification", "What level do you wish to play "..data[j].name.."?", { "Cancel", "All-Star", "Rookie" }, onLevel ) end end
Here is the output from the code. The “made it to inner showalert” only prints after user interacts with the last alert.
20:34:29.555 j 1 id false
20:34:29.555 j 2 id true
20:34:29.555 j 3 id false
20:34:29.555 j 4 id true
20:34:29.555 j 5 id false
20:34:40.542 made it to inner alert
