logging - 我的日志消息有问题,我无法解决
问题描述
所以我正在尝试开发一个可以显示字符串和日志的消息,但奇怪的是,日志只显示最后一个字符串,而不是 1 条消息中的事件。有人可以帮忙吗?
function printToLog(string, log)
if logPage.fromMainMenu == false then
popupPage = logPage
else
logPage.fromMainMenu = true
popupPage = logPage
end
prepareMenuPage(popupPage)
local areYouSureText = getItemByName(logPage.items, "logText")
setFont(areYouSureText.font)
if log ~= true then
areYouSureText.logText = string
_G.table.insert(g_printLogList, string) -- insert string into log
print(string)
else
for i = 1, #g_printLogList do
areYouSureText.logText = g_printLogList[i]
end
end
end
解决方案
如果不查看表结构、输入值、预期内容或至少解释,就很难进行调试,但我会尝试。
这让我很困惑
if logPage.fromMainMenu == false then
popupPage = logPage
else -- if it isn't false...
logPage.fromMainMenu = true -- then it's already true. no need to set it true here
popupPage = logPage
end
我想知道是否是为了评论
if logPage.fromMainMenu == false then
popupPage = logPage
else -- logPage.fromMainMenu = true
popupPage = logPage
end
但是,如果是这样的话,你就不需要 if...else - 他们正在做同样的事情。也许你的意思是把它的价值转移给另一个?
if logPage.fromMainMenu == false then
logPage.fromMainMenu = true
end
popupPage = logPage
无论哪种方式,我认为正在发生的事情是您每次循环时都用一个条目替换整个内容。你真正的意思是在每个循环期间附加。areYouSureText.logText
g_printLogList[i]
areYouSureText.logText
g_printLogList[i]
for i = 1, #g_printLogList do
areYouSureText.logText[ #areYouSureText.logText +1 ] = g_printLogList[i]
end
编辑:
相同的区别,只是附加带有连接的文本而不是..
areYouSureText.logText = areYouSureText.logText ..'\n' ..g_printLogList[i]
推荐阅读
- delphi - 使用 dbExpress 时的内存问题
- fullcalendar - 两天内的自定义时间线视图,但仅显示两者之间的时间
- python - 将df的所有列动态转换为numpy
- python - 试图制作条形图,bar() 缺少 1 个必需的位置参数:'height'
- python - Python 3. 如何运行外部程序并执行命令?
- java - 为什么在两个项目中从左到右为 ImageView 设置动画时,我收到不同的结果?
- python - 如何避免重复迭代,并打印语句 2 次
- java - 如何识别 Gremlin 查询返回的内容?像顶点或边或标签等
- angular - 强制图表重绘或更新 Chart.js
- oracle - 如何使用触发器将基表的所有更新列添加到审计表的多行?