(JavaScript) Issue

I’m getting an error with my code. The error is “Assets/Scripts/Timer.js(9,54): BCE0023: No appropriate version of ‘float.ToString’ for the argument list ‘(int)’ was found.” Here is my code.

#pragma strict
var timer : float = 60.0;

function Update () 
{
	timer -= Time.deltaTime;
}

function OnGui()
{
	GUI.Box(new Rect(10, 10, 50, 20), "" + timer.ToString(0));
}

I’m still new to JavaScript to please excuse me.

The error message basically means that you’re calling a version of a method that doesn’t exist. Usually this means you’re passing arguments where you shouldn’t be, passing arguments of the wrong type, or not passing arguments when you should be.

The ToString() method doesn’t accept arguments, so you shouldn’t be passing the 0 inside it. Get rid of that, and that error will go away.

ToString does accept arguments: Standard numeric format strings - .NET | Microsoft Learn But not an integer. Also, OnGUI is spelled wrong and won’t be called.

–Eric

1 Like

I have a two-month-old baby and my brain doesn’t always do its best work anymore. Thanks for the correction, @Eric5h5 . :wink: