0

I am designing an Odd One Out round for a game that I am developing, every time a button is pressed, the onButtonEvent function is supposed to check if the word selected is the odd one out and then refreshes the buttons with different words.

The words are updating and the value assigned to each button is updating, I have been printing it out to the console. I think the problem is when I assign right[num] = t.value the only values that go into the table are the first 3 values that were originally assigned to the buttons. Why is this not being updated?

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()
hjpotter92
  • 78,589
  • 36
  • 144
  • 183
Gooner
  • 387
  • 2
  • 23

1 Answers1

0

The problem is probably here:

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

You have nothing set in the elseif statement.

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
  • I have put something in that statement now, but it is not that. the only values going into right[num] are the the values of the first 3 buttons e.g. first options PANTS JUMPER HAT, when I select one, its goes into the table and then the buttons get refreshed with new words. When I click on a new word the previous value is still being put into the table – Gooner Jan 18 '13 at 13:53
  • 1
    I found out how to get the right values into the array. Since posting this question I was advised not to keep calling my displayButtons() function as this was only adding more objects on top of the previous ones. So instead I have used a function to change the labels for the next set of words, this is also where I am updating the btn1.value – Gooner Jan 21 '13 at 16:51