首页 > 解决方案 > 我的日志消息有问题,我无法解决

问题描述

所以我正在尝试开发一个可以显示字符串和日志的消息,但奇怪的是,日志只显示最后一个字符串,而不是 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  

标签: loggingprintinglua

解决方案


如果不查看表结构、输入值、预期内容或至少解释,就很难进行调试,但我会尝试。

这让我很困惑

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.logTextg_printLogList[i]areYouSureText.logTextg_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]

推荐阅读