Storing Application.LoadedLevel As a variable not working.

Hi,
I have this code where I want lvll to equal the current scene’s index number

	if (steps == stepsneeded) {
	//pkmn = Random.Range(1,4
		Debug.Log("BATTLE");
		lvll = Application.loadedLevel();
		SendMessage("ReturnLVL",lvll);
		
		Application.LoadLevel(8);
	}

The problem is that when I run my project, the console says: It is not possible to invoke an expression of type ‘int’

Shouldn’t this work being that Application.LoadedLevel returns an int?

1 Answer

1

Application.loadedLevel is a property, not a function. Remove the brackets and you’ll be fine :slight_smile:

It's saying that the function SendMessage does not accept the parameters you have provided. SendMessage takes the function name you wish to call - "RunAway" - and one optional argument to pass to that function. You have tried to pass multiple objects, you can only pass in one, or none. You should modify the receiving function to accept ReturnLVL instead.

Okay, how would I allow the function to recieve another function? would it just be function RunAway (ReturnLVL : function) { } ?

Ah, I misunderstood, I thought ReturnLVL was a class. Whatever you are trying to pass into the RunAway function, you should collect into a class and pass an instance of that. Or, ideally, call the RunAway function directly using an instance of whatever script it belongs to.