Need to understand better

I’m struggling to understand why accessing to the getter method GetAnswer() using the reference to “QuestionSO question”, is working to get the answers display on the buttons

instead of the “QuestionSO answers” that was created in the QuestioSO script, that tecnically hold the data for the answers array

…i find it hard to make sense…this thing i think is a very important step, and if i fail to fully grasp the logic on it, i will have hard times every time i need to use any getter methods

answers is not publicly accessible. It is private to QuestionSO and we do not have access to it, so we use the getter that we created to access it. It is private because we want to protect it from the outside. Nothing from the outside can access it, so nothing can accidentally change it. Except the inspector, here, but that is what we need to set up the answers

I think you’re confusing QuestionSO question as the same as the question field in the QuestionSO class. QuestionSO question is actually a QuestionSO object variable named “question”. This means you can change it any name you want so it might not confuse you here.

2 Likes

I think this is the correct answer. I read the OP several times and only really understood it after I read this answer. We’re not accessing the question from QuestionSO, we’re accessing question from Quiz

2 Likes

Yes the same variable name confused the heck out of me.
Plus if i wanted to change the name of the variable, to one that make more sense, i needed to reassign in the inspector the scriptable object with the question inside.
Missing this step was creating most of the confusion, because unity remembers what was assigned to a variable in the inspector only if it has the same name.
Thanks for helping!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms