I have a problem with the else command(SOLVED)

Hello this will be my first post thanks for such great course and community

So i was using the If Else and was going fine until i started adding more code guess = (max + min /2 ;

but only from line 37 39 seemed to cause the else problem tired a few ways moving the { around trying other positions i even added more { but nothing i do seems to help.
I am using Visual Studio instead of MONO could be where my problem is

THANK YOU hope i explained well enough

Kind Regards Conna

Your else if works very similar to your if statements in that they check some logic which is inside regular brackets (...) then you wrap what actions you wish to be taken if the logic returns true in curly brackets {...}.

On line 36 you have an if else(...) statement with a logic check but then don’t have a set of curly brackets to tell Unity what to do if the keydown is true. On lines 41 and 44 you have a set of curly brackets that aren’t doing anything and are likely causing you a number of issues as they follow on from a print statement so Unity doesn’t know why they’re there.

On line 44 your else if statement does have the regular and curly brackets so should work without issue.

thanks for fast response it seems once i sorted that problem out with the {} it seems there is another problem or something i am missing i am little confused.The {} still kind of get me :stuck_out_tongue: Capture

am i now missing a set of brackets ?

hey thank you for fast response i tried what you said i thought this look better then i see the red at the bottom! am really quite new but really enjoying the learning process Capture|655x500

You’ve got to print statements for down arrow pressed. The second ones comes after the end of an if else. Because of this Unity now treats the if statement as finished so now when you say else if it’s getting confused.

Thank you very much it was the {} making all the problems like you said cheers

look at the code i made for you… hope this helps
image

1 Like

Just to note - you can just copy/paste your code into the forum and apply the code formatting characters both before and after the code. This is much more useful than screenshots, especially for those that try to help you as they can simply copy/paste parts of your code back into their replies without having to type it all out. Please see the link below regarding code formatting within your posts.

Screenshots are, of course, very useful for error messages, and details from within the Unity editor itself though.

Hope this helps :slight_smile:


See also;

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

Privacy & Terms