I wanted to post how I tried to follow Noddy's suggestions, and it works!!! I think I should have been able to do it all in array functions without so much stuff in each Toggle Button (like batch process all "right" buttons one way and "wrong" another way). BUT, this works so I am posting in case anyone wants to revise to make it cleaner and/or to help Noobs like me trying to decipher what Noddy wrote :)
Side Note: Extra Stuff showing
I've left the signals in but we don't need "right/wrong" ones so you can take those out.
Leaving in the rrchallenge_collected but you don't need that either. It's for the 100 points going into the main GUI control when they complete rrchallenge2 (ie so I'll remember it needs to be in there but it won't be in this challenge scene since they have to finish both to get points).
Top code:
extends Control
export var value = 100 # export is for scoring stuff I'll use later so not important to this Q&A
var array1 = [1, 2, 3, 4, 5, 6]
var array2 = []
var length = array2.size() # I don't know if I actually need this part
signal rrchallengecollected
signal rrchallengeright
signal rrchallenge_wrong
func _ready(): #not sure I need these either?
array1.size()
array2.size()
Toggle Buttons Code
#When they toggle a correct button (I didn't list all 12 buttons, just 1 right/1wrong)
func _on_cardGET_toggled(button_pressed):
if button_pressed==true:
array2.insert(0, "1") # insert lets me put the right value text "1" at right position [0]
print(array2)
emit_signal("rrchallenge_right")
else:
array2.erase("1") # untoggled so take out element 1...erase works, remove doesn't, long story why
print(array2)
Result: array2 now shows [1] :D
#When they toggle a "wrong" button
func _on_cardAGE_toggled(button_pressed):
if button_pressed==true:
array2.append("A") #appending A adds it to end so it will make size wrong (we want this, otherwise it can replace a right answer in its index position)
print(array2)
emit_signal("rrchallenge_wrong")
else:
array2.erase("A")
print(array2)
Result: if they untoggle it removes A from end, or if they left it untoggled array2 stays as it was before
array2 now shows [1, 7] if cardGET and card AGE were both toggled on-- if they toggled cardAGE back off, it shows [1] again! This updates as such for each toggle added/removed.
NOTE: I did the other 5 correct and other 5 incorrect buttons like above, then, at the end under my "submit" button code
End: Submit/Check Code
func _on_Submit1_pressed(): #the button they press when they've toggled all their toggles on/off to signify they're done and ready to check answers
if array2.size() > 5:
print(true)
if array1.size() == array2.size():
$Success.show() #this is the label saying "woohoo you got it"
$GotoChal2.show() #this is a new button that takes them to the next challenge
else:
$Fail.show() #label saying "try again"
$TryAgainChal1.show() #button to restart scene
Note on restart scene for Try Again: I haven't connected it and made that happen but hoping I can just mimic my "getscenetree" change scene thingie from start menu lol). I think just restarting the scene will be easier than resetting both arrays and hiding stuff and all that.