- Home /
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?
Answer by Gizmoi · Jan 28, 2013 at 12:53 AM
Application.loadedLevel is a property, not a function. Remove the brackets and you'll be fine :)
Thanks for the help but I am having one other problem..
function Update () {
if (Application.loadedLevel == 8){
Send$$anonymous$$essage("RunAway", ReturnLVL.lvl, ReturnLVL.positionx, ReturnLVL.positiony,ReturnLVL.positionz);
}
}
function ReturnLVL (lvl : int,positionx : int, positiony : int, positionz : int){
Debug.Log(lvl);
Debug.Log(positionx);
Debug.Log(positiony);
Debug.Log(positionz);
}
When I use this it says No appropriate version of UnityEngine.Component.Send$$anonymous$$essage for the argument list (String, system.object,system.object,system.object,system.object) was found.
How can I fix this error?
It's saying that the function Send$$anonymous$$essage does not accept the parameters you have provided. Send$$anonymous$$essage 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 ins$$anonymous$$d.
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.
Your answer
![](https://koobas.hobune.stream/wayback/20220613091713im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Variable data type for two ints (x and y) in inspector 3 Answers
Problem with variables,Problem with identifying a variable 2 Answers
How can i save a int for multiple texture. Please Read. 0 Answers
controlling the increment in the variable 1 Answer
I can't print a int.ToString() variable in a guiText.text 1 Answer