0

我正在为我正在开发的游戏设计一个奇数轮,每​​次按下按钮时,该onButtonEvent功能应该检查所选单词是否是奇数,然后用不同的单词刷新按钮。

文字正在更新,分配给每个按钮的值也在更新,我一直在将其打印到控制台。我认为问题在于,当我分配right[num] = t.value进入表格的唯一值是最初分配给按钮的前 3 个值时。为什么这个不更新?

local function onButtonEvent( event )
    local t = event.target
    --local phase = event.phase
    if event.phase == "release" then
        --num = num + 1
        displayBtns()
        right[num] = t.value
        print(right[1])
        print(right[2])
        print(right[3])
        print(right[4])
        -- --s3 = table.concat(right)
        --print(s3)
        if right[num] == answers[num].right then
                print("correct!")
        elseif right[num] == answers[num].wrong then
                -- t.alpha = 0
                -- select.alpha = 1
                print("incorrect!")
        elseif right[num] == answers[num].wrong2 then
        else
                print("incorrect!")
        end
        num = num + 1
        num2 = num2 + 1
        s3 = ""
        -- display.remove( btn3 )
        -- btn3 = nil
        -- display.remove( btn2 )
        -- btn2 = nil
        -- display.remove( btn1 )
        -- btn1 = nil
    end
    --num = math.random(1,#t)
    s3 = ""
end
 function displayBtns()
btn3 = widget.newButton{
    default = "images/Round4_blue_button.png",
    label = answers[num].right,
    fontSize = 22,
    labelColor = { default={ 255, 250, 250}, over={ 0, 0, 0,} },
    onEvent = onButtonEvent
}
 btn3.value = answers[num].right
print(btn3.value)
 btn2 = widget.newButton{
    default = "images/Round4_blue_button.png",
    label = answers[num].wrong2,
    fontSize = 22,
    labelColor = { default={ 255, 250, 250}, over={ 0, 0, 0,} },
    onEvent = onButtonEvent
}
btn2.value = answers[num].wrong2
print(btn2.value)
 btn1 = widget.newButton{
    default = "images/Round4_blue_button.png",
    label = answers[num].wrong,
    fontSize = 22,
    labelColor = { default={ 255, 250, 250}, over={ 0, 0, 0,} },
    onEvent = onButtonEvent
}
btn1.value = answers[num].wrong
print(btn1.value)
print("----------")
  --btn3.label = answers[num].right
-- p1Button = display.newImage("images/SinglePlayer_button.png", 90, 140)
-- p2Button = display.newImage("images/2Player_button.png", 90, 220)
 -- p1Button.touch = onSceneTouch
-- p1Button:addEventListener("touch", p1Button)
 -- p2Button.touch = onSceneTouch1
-- p2Button:addEventListener("touch", p2Button)
btn1.x = 90;  btn1.y = 245
btn2.x = 240; btn2.y = 245
btn3.x = 390; btn3.y = 245
-- p2Button.x = 240; p2Button.y = 260
 end
displayBtns()
4

1 回答 1

0

问题大概出在这里:

elseif right[num] == answers[num].wrong2 then
else
    print("incorrect!")
end

elseif您在声明中没有设置任何内容。

于 2013-01-18T13:02:23.893 回答