Just took a look at your project. The main problem is that your initializing your "answer" array with int
values (1, 2, 3, 4, 5, 6), but you're appending string
values to the array that you're comparing ("1", "2", "3", "4", "5", "6"). When you eventually call arrays_have_same_content
, that method is returning false
because the int
values in the answer array don't match the string
values in the match array.
To fix that, you need to use the same data type in both arrays. Either strings or ints will work, but they should be the same.
Since you're using "letters" for incorrect choices (which can't be an int
), I'd recommend that you just use strings everywhere.
So, at the top, initialize your arrays like this:
var array1 = ["1", "2", "3", "4", "5", "6"]
var array2 = []
(notice, the 6 values added to array1 are string
, not int
)
And, notice that array2 is simply empty.
Then, you can code each *_toggled
function like this, although obviously, append and erase the correct character in each function.
func _on_cardAGE_toggled(button_pressed):
if button_pressed==true:
array2.append("1")
else:
array2.erase("1")
Above, the given character is added to the array when the button is pressed and erased when the button is unpressed. That ensures that the array will always have only 0 or 1 copy of the character no matter how many times the button is pressed - which is important when you finally compare it to the answer array.
If you code all of the button handling functions like the above, your scene should work as you expect.
I would also say that, while what you have here will work, it's laborious to create, error-prone to code, and just requires a lot of work to manage a single "quiz". There are certainly better ways to do this kind of thing, but the above should get you working.
Let us know how you get along.