【问题标题】:Lua corona SDk convert correct answer to percentage % using if elseLua corona SDK 使用 if else 将正确答案转换为百分比
【发布时间】:2015-11-23 14:30:13
【问题描述】:

我正在尝试使用 Corona SDK 找出一个简单的真假测验应用程序。现在我可以使用 text= myData.ScoreCount 计算正确答案 请正确:

 local textoPontuacao = {
       text= myData.ScoreCount,-- correct score is counting
         x = ganhou.x + 310,
         y = ganhou.y - 47,
         width = 700,
         font = native.systemFontBold,
         fontSize = 36,
        }
        local t=50 -- total questions
        local c=textoPontuacao -- textoPontuacao counts correct answer
        local pc=(c/t)*100
        local r

       if pc >=60 and pc<70 then
       r = "Not Bad!"
       elseif pc >=70 and pc<80 then
       r = "Good Match!"
       elseif pc >=80 and pc<95 then
       r = "Very Good Match!"
       elseif pc >=95 and pc<101 then
       r = "Excellent!"
       else
          r = "You have to Think"
        end

        local textoPon = display.newText( r )-- normally if i use textoPontuacao instead of r, it prints correct Answer.
       textoPon:setFillColor( 1,1,1 )
       sceneGroup:insert(textoPon)

现在我想从 if else 语句中打印字符串值而不是正确答案。如果我使用 textoPontuacao 进行打印,则会显示正确答案。有人帮助解决这个问题将不胜感激。而且我也需要将正确答案转换为百分比,但不清楚如何?我是 lua 和 corona SDK 的新手,只是想定制一个简单的游戏。

【问题讨论】:

  • 究竟是什么不在这里工作?您似乎正在将表格除以一个数字。这会给你一个错误吗?
  • 嗨,谢谢,我收到一个错误,尝试在本地'c'(表值)中执行算术,它是表--------本地 textoPontuacao = { text= myData .ScoreCount,--正确的分数是计数x = ganhou.x + 310, y = ganhou.y - 47, width = 700, font = native.systemFontBold, fontSize = 36, }
  • 是的,那是因为您试图将表格除以数字。你的意思是local c = t.text 在那里算数吗?
  • 是的,我现在试过了,它说一个错误,尝试索引一个本地't'(一个数字值)
  • 抱歉,我的意思是 local c = textoPontuacao.text 或 local c = myData.ScoreCount 或只是 local pc = (myData.ScoreCount / t) * 100。

标签: math lua coronasdk


【解决方案1】:

虽然我终于解决了这个问题,但我要感谢 Etan Reisner 先生,他帮助了我很多。我很感谢他。现在我说这个问题,我们之前使用了 local textoPon = display.newText(r) 现在我使用了 local textoPon = display.newText(r,195,150, "Arial", 35) 并且它已经解决了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-28
    • 2020-08-07
    • 1970-01-01
    • 1970-01-01
    • 2020-01-06
    • 2020-05-24
    • 2021-08-30
    • 2021-01-15
    相关资源
    最近更新 更多