No slot for text on NumberWizard object

Thanks in advance for your help with this problem.

I followed along with the tutorial until around 14:00 I added the public Text text and the text.text ToString, which is supposed to create a slot on the NumberWizard object in Unity. However it does not create that slot for me, and I get the following error from the line of code that limits the maximum number of guesses:

Assets/NumberWizard.cs(10,33): error CS1519: Unexpected symbol ‘10’ in class, struct, or interface member declaration

I have gone line by line from the tutorial comparing my script to his, and I don’t see any differences that would lead to these problems. The only difference is that I modified my script to guess random numbers between the minimum and the maximum rather than the mid point, but I don’t think that would cause these issues.

Here is a screen shots of my script (I will add a screen shot of my inspector in the next post):

Here is a screen shot of my inspector

int MaxGuessesAllowed = 10;

From a naming conventions perspective it would be better to use a lowercase “m” for “maxGuessesLlowed” also. It will keep the code consistent with what you already have. :slight_smile:

Doh! Thanks for your help!

1 Like

You are very welcome :slight_smile:

I would just like to know how that fixed the Text option in the inspector. I am still currently having the same problem, and have run over both the course code lines, OP’s lines and my own; and are all the same. But mine still won’t acknowledge the string.

1 Like

Possibly some differing issues so I will see if I can cover most bases…

Firstly, if you want to expose one of your variables within the Inspector you will need to set its access modifier to public.

Then you need the Type of the variable you are going to expose, in this case an int (Integer), finally you need the name of the variable, this can be of your choosing but is best to name them to something relevant. Finish the statement with a semi-colon.

So, as an example;

public int maxGuessesAllowed;

This defines the variable and will display it within the Inspector (assuming you have no other code issues which prevent the code from building).

You can of course initialise this variable at the same time you declare it, to do so you aimply state the value it equals before the semi-colon for the statment, e.g.

public int maxGuessesAllowed = 10;

This is exactly the same as the firat example but now we are also initialising the value to 10.

Hope this helps, if not pastr your code into a replt along with relevant screenshots :slight_smile:

Also, when you are writing you code it is a good habit / practice to make your class level variables (fields), properties and methods private and only increase their scope as needed by your game / application.

1 Like

That helped me out alot! thank you! I re-worked the code, and noticed I had 1 closing parenthesis wrong, and that is what was causing my problem.

Thank you again!

1 Like

Glad you resolved the issue and got it working - well done :slight_smile:

I have done everything right according to the course but it does not work what to do?
p.s. Sorry they are in the wrong order. (fixed)

Hello @AroBoy,

Thank you for the screenahots, just so you are aware you can literally just paste your code into the posts - this makes it a little easier to manage.

So, what is the specific issue? When you say it isn’t working, what is not happening that should be?


See also;

I had the same issue and ran MonoDevelop in Debug mode to point out the culprit! I needed your post to think of it though
:nerd:

1 Like

Privacy & Terms