- Home /
Why isn't the best overload method not compatible with the arguments list?
I know that this is a common question here, but I've looked everywhere and I cannot find a solution anywhere. The exact error message is "The best overload for the method 'SideWalls.ScoreSystem()' is not compatible with the argument list '(String)'."
The Code for Sidewall.js is
#pragma strict
function OnTriggerEnter2D (HitInfo : Collider2D) {
if (HitInfo.name == "Ball") {
var wallName = transform.name;
ScoreSystem (wallName);
}
}
function ScoreSystem() {
}
and ScoreSystem.js is
#pragma strict
static var Player1Score : int = 0;
static var Player2Score : int = 0;
public var wallName : String;
static function Score (wallName : String) {
if (wallName == "rightWall") {
Player1Score += 1;
}
else {
Player2Score += 1;
}
Debug.Log("Player 1: " + Player1Score);
Debug.Log("Player 2: " + Player2Score);
}
What exactly do you try to accomplish? The error says that you try to call a function called "ScoreSystem" inside the SideWalls class and that the function does not have any overload variant that can exempt a string.
Looks more to me like you are trying to call the fuction "Score" inside the calss "ScoreSystem"
That would be done by calling
ScoreSystem.Score (wallName);
ps: Creating a variable name with the same name of a functions parameter does not help to prevent confusion.
Answer by Baste · Mar 18, 2015 at 12:06 PM
This code:
function OnTriggerEnter2D (HitInfo : Collider2D) {
if (HitInfo.name == "Ball") {
var wallName = transform.name;
ScoreSystem (wallName);
}
}
function ScoreSystem() {
}
Is what's causing the problem. You've got an (empty) function named "ScoreSystem", that takes no arguments. In your OnTriggerEnter, you're calling it with the wallName argument.
As to what you're expecting ScoreSystem(wallName) to do, I've got no clue.