If you’d like to see the variable printed in your app, try something like this:
[lua]local myFont = native.systemFontBold
local alertCount = 1
local alertArray = {}
function alert(theText, append)
– If “append” is set to “false”
if not append then
– Remove any previous text blocks
for i,item in ipairs( alertArray ) do
item:removeSelf()
end
– Reset the counter
alertCount = 1
end
– Create a new “object” on the alertArray that contains a “quassi-variable” called “handle”
alertArray[alertCount] = { handle = “” }
– Set the “handle” variable within our newly created “object” to a newly created text block
alertArray[alertCount].handle = display.newText(theText, 20, alertCount*20, myFont, 20 )
– Set the color of the text block
alertArray[alertCount].handle:setTextColor(255,0,255)
– Increase our counter by one so that we can have more lines, should we choose to set “append” to true
alertCount = alertCount + 1
end
–[[
Usage Example:
function doSomeMath()
local problem = 2 + 2
alert(“yo”, false)
end
function doMoreMath()
local problem = 4 + 4
alert(problem, true)
end
doSomeMath()
– shows: 4
doSomeMath()
doSomeMath()
doSomeMath()
– doMoreMath uses the “append”:
doMoreMath()
– shows: 4
– 8
doMoreMath()
doMoreMath()
doMoreMath()
– shows: 8
– 8
– 8
– 8
–]][/lua] [import]uid: 616 topic_id: 5793 reply_id: 22193[/import]