[SOLVED] min Variable is Assigned but Never Used

This is for the lecture, “Importing Previous Number Wizard Script.” Below is my code. I am following the tutorial video exactly but getting the following warnings from Unity. When I try to run my game, the “higher” and “lower” buttons change the text UI element from “500” to “0” instead of to the expected values of “750” and “250” etc. I’m sure this behavior is caused by the fact that my variables are not being used. What can I change in the code to make the script use my variables as demonstrated by the lecture video? Thanks in advance for your help!

“Assets/Scripts/NumberWizards.cs(20,21): warning CS0219: The variable `guess’ is assigned but its value is never used.”

“Assets/Scripts/NumberWizards.cs(19,21): warning CS0219: The variable `min’ is assigned but its value is never used”

1 Like

If you look at your StartGame() method you’ll see that you’re re-defining your variables within the scope of StartGame().

Replacing the lines like
int max = 1000;
with
max = 1000;
will use the existing variables in your NumberWizards class and not define a new ones. In other words, don’t put the variable type before the name, otherwise the compiler will think you’re defining a new variable.

Phil

1 Like

Thanks for the reply, Phil! I actually uploaded the wrong screenshot. Oops! I have already made the changes exactly as you described and I’m still experiencing the same issue. Any ideas what else could be wrong?

I’m honestly not sure what the problem was aside from the one you mentioned, but the game is now working as expected.

Thanks for your help!

Glad to hear it’s now working.

Don’t forget to change your original post’s title to [Solved].

Phil

1 Like

It could’ve been simply that you forgot to hit save after making the changes - I’ve done that plenty of times :persevere:

1 Like

Privacy & Terms