(solved) i coppied the code in this lecture exactly and have double checked. still reciving errors

this is the code I have witch should be identical to the code in the video ( half way through), can someone please point out what I have missed or done wrong.

I am running unity 4.6.9.
this is my code
using UnityEngine;
using System.Collections;

public class NumberWizard : MonoBehaviour {

// Use this for initialization
int max = 1000;
int min = 1;
int guess = 500;

void Start () {
	print ("Welcome to Nmber Wizard");
	print ("Pick a number in your head, but dont tell me");
	
	print ("The highest number you can pick is " + max);
	print ("The lowest number you can pick is " + min);
	
	print ("Is the number higher or lower than " + guess);
	print ("up-arrow for higher, down arrow for lower, return for equal");
}

// Update is called once per frame
void Update () {
	if (Input.GetKeyDown(KeyCode.UpArrow)) {
		//print ("up-arrow key was pressed");
		min = guess; 
		guess = (max + min) / 2;
		print ("Is the number higher or lower than " + guess);
	} else if (Input.GetKeyDown(KeyCode.DownArrow)) {
		//print ("down-arrow key was pressed");
		max = guess;
		guess=  (max +  int) / 2;
		print ("Is the number higher or lower than + guess"); 
	} else if (Input.GetKeyDown(KeyCode.Return)) {
		print ("i won");
	}
}

}

thank you.

edit: I have now fixed the red error and only need to fix the <RI.Hif> error

edit: I have now fixed 4 of the errors to do with the " instead of an ; after the min + max were being divided by 2.

Good spot - it’s always more satisfying when you find these things yourself :slight_smile:

You also have a missing semi-colon on the end of line 33.

Note, when posting code queries its often a lot easier to just copy/paste the code directly into your post rather than screenshots. It allows the people who are trying to help you to copy/paste bits of it as an example/solution, rather than having to type the whole chunk in themselves.


See also;

Forum User Guides : How to apply code formatting within your post

1 Like

thanks

I now just have 1 error


and this is what my code is.

using UnityEngine;
using System.Collections;

public class NumberWizard : MonoBehaviour {

	// Use this for initialization
	int max = 1000;
	int min = 1;
	int guess = 500;
	
	void Start () {
			print ("Welcome to Nmber Wizard");
			print ("Pick a number in your head, but dont tell me");
				
			print ("The highest number you can pick is " + max);
			print ("The lowest number you can pick is " + min);
			
			print ("Is the number higher or lower than " + guess);
			print ("up-arrow for higher, down arrow for lower, return for equal");
		}
			
	// Update is called once per frame
	void Update () {
		if (Input.GetKeyDown(KeyCode.UpArrow)) {
			//print ("up-arrow key was pressed");
			min = guess; 
			guess = (max + min) / 2;
			print ("Is the number higher or lower than " + guess);
		} else if (Input.GetKeyDown(KeyCode.DownArrow)) {
			//print ("down-arrow key was pressed");
			max = guess
			guess = (max + min) / 2;
			print ("Is the number higher or lower than + guess"); 
		} else if (Input.GetKeyDown(KeyCode.Return)) {
		print ("i won");
		}
	}
}
1 Like

You are missing a semi-colon at the end of that statement.

p.s. the article I shared shows you how to apply the code formatting so that all of the code is formatted, if you only paste it in, some bits won’t be :slight_smile:

1 Like

thanks again.

1 Like

No problem, any time :slight_smile:

Privacy & Terms