Cannot implicitly convert type 'void' to 'boolean'

Hi everyone!

New to Unity, C# and programming! Checked for existing answers but haven’t provided a solution.

I have a scene with GUI buttons that load a stage/map from another script. I want to instantiate certain prefabs for certain stages/maps.

So, for example if “Map 01” is loaded then create these objects.

I’ve given it a go but I get this error when I run the code! I’m guessing it’s because my ‘if’ statement returns void instead of a boolean but I don’t know how to change that. Any help would be HUGELY appreciated.

Error (InstantiateObjects Script below)

	if (stage.Load (1)) {

InstantiateObject Script:

public class InstantiateObject : MonoBehaviour {

	MapMaker stage;

	public GameObject myObject;
	public Vector3 spawnSpot = new Vector3(-4,0,5);

	void Start() {
		stage = GameObject.Find ("MapMaker").GetComponent<MapMaker> ();
	}
	
	void Update () {
		if (stage.Load (1)) {
			GameObject ObjectSpawn = (GameObject)Instantiate(myObject, new Vector3(-4,0,5), transform.rotation);
		}
	}
}

MapMaker Script:

	void Start () {
	public void Load (int stage_id) {
		switch (stage_id) {
		case 1:
			MakeMap (new Map01 ());
			break;
		case 2:
			MakeMap (new Map02 ());
			break;
		}
	}

Game UI Script:

public class GameUI : MonoBehaviour {

	MapMaker stage;

	void Start () {
		stage = GameObject.Find ("MapMaker").GetComponent<MapMaker> ();
	}
	    
	void OnGUI () {
		GUI.Box(new Rect(10,10,100,240), "Stages");
		
		if(GUI.Button(new Rect(20,40,80,20), "Stage 1")) {
			stage.Load (1);
		}
		
		if(GUI.Button(new Rect(20,70,80,20), "Stage 2")) {
			stage.Load (2);
		}
	}
}

Ok… here is the problem

This line

if (stage.Load (1))

the if statement is expecting a bool. if “true” execute… if “false”, ignore…

The stage.Load function, however, doesn’t return a bool as a value.

 public void Load (int stage_id) {...

The if statement is calling it and getting an empty response as an answer.

for that to work, it would have to be

public bool Load (int stage_id) {..

and each switch would have to have a boolean return value (“return true” or “return false”)