A small piece of code i cant figure out how to convert.

Hi all,

I am back again with some more C# to Unityscript conversion problems.

I have converted almost all of this C# script except for the last bit.

 private string DispTime()
{

}

I tried to change the above line of code into a function and cant get it right.

I made a string variable out of DispTime, which does not work because its being called in another part of the script.

I have looked around and haven’t really found any reference that can help me out with converting this.

Anyone got any ideas?

Thanks.

wouldnt it just be

private function DispTime()
{

      return yourString;
}

If you wanted a literal conversion, it would be

private function DispTime () : String
{
}

If you leave the type out, it’s inferred from the return value.

–Eric

Hmmm.

Now i am getting getting errors inside the function using either method suggested.

The full code is.

private function DispTime() : String
{
          if (jigsawPuzzle.time<60)
          {
             return string.Format("{0:0} seconds", jigsawPuzzle.time);
          }
             else
          {
             return string.Format("{0:0:0} minutes", jigsawPuzzle.time/60);
          }
}

The error i am getting is from both the return statements, the error is Unknown identifier: ‘string’.

Thanks for the help guys. :slight_smile:

In JS it’s String, not string.

–Eric

seriously?

edit what he said

HAHA,

Sorry about that guys… my brain is a little fried at the moment from all this code.

Thanks for the help. :slight_smile: