icm week #6: arrays and chance
this week's icm homework was a DOOZY.
i wanted to make a simple sketch involving arrays which would hopefully be the first step toward my midterm next week (a sex ed trivia game). the idea was to create rows of buttons which contained 9 "wrong" selections (red) and 1 "right" selection (green). if you either chose the right button OR chose 3 wrong buttons, the row of 10 would fade away. sound simple? not so much.
i initially had only one class, the buttons, and in my main tab i had set up 10 different arrays of the same class. but i instinctively knew that this was the wrong approach, which dan confirmed when i went to his office hours. i ended up making an array of 10 rows, which in turn each contained an array of 10 different buttons.
dan and the icm list also helped out with 1) getting the colors to stay and 2) getting the rollover function to work. initially, i was just drawing the rollover function without any conditionals, but it turns out that the rollover was disabling any color i added to the buttons after they were clicked, so none of the red or green was staying put. the solution was to incorporate state variables into my code to override the rollover function when they were enabled.
last, but not least, i had to enable the fading function. figuring out that i needed a counter to determine when to fade was the easy part. once i got my rows and buttons where i wanted them (which was no small feat!), i soon discovered that just enabling the fade boolean when the mouse was clicked made ALL of the buttons fade off the screen -- not what i wanted! i eventually discovered (admittedly through trial and error) that i had to include an additional condition in my row class and count function -- that y = y. seems simple enough but it actually took me forever to come to that conclusion. of course, now that i think about it, it makes perfect sense, because how is the program supposed to know that only one row fades unless you specify it?
it took a lot of work but i totally feel comfortable with this now, and more importantly, everything i did to get to this point makes sense. all good signs pointing forward.
here's the final product: