function puzzleProgress() : float
{
return (piecesPlaced/pieceCount) * 100;
}
So the code calls on two functions to check the progress of the game, piecesPlaced (how many of the pieces from the starting amount have been placed in their right spot.)
And pieceCount (how many pieces have not been placed yet and still remain in play)
With the code i have up there for Unityscript i get the following error.
BCE0051: Operator ‘/’ cannot be used with a left hand side of type ‘function(): int’ and a right hand side of type ‘function(): int’.
typecast the results from the functions as float, for example (this is C# code, look for js code on the webz): float result = (float)(function1())/(float)(function2()) * 100; function1 and function2 return int.
piecesPlaced/pieceCount is meant to be piecesPlaced()/pieceCount() cause the error implies that this are functions and functions need () to return anything
the compiler would never warn you that int / int will yield in a crap result cause it devides without any fractions but modulo reminder
I would strongly recommend to follow basic .NET naming schemes, that saves you such headaches, which your AS / JS naming scheme definitely doesn’t
Properties always tart with upercase and after that camel
Functions always start with uppercase and after that came
local variables start lowerCase and after that camel
class variables / instance variables either lowercase and then camel or underline lowercase camel ie _myVariable
that way you will never mix variable and function at all again
also the code is not hte C# equivalent. the equivalent would be
Yes they both are functions piecesPlaced() : int and pieceCount() : int
I am aware functions start with uppercase and then camel e.g. function OnGUI()
However the scripts that i am trying to convert do not follow this rule and to avoid confusion when cross checking code i have decided to leave it this way.
Yes i forgot to put in the get, thanks for reminding me.
I am still looking through typecasting to try and solve this error, but am having trouble finding some examples that i can understand fully, can anyone point me in a direction to some basic typecasting examples.