You need to be using == not =
= sets a value
== compares values
So your:
if (currentPlayer = 1)
is always returning true, and is setting current player to 1
(and then because it tests true (i.e. the script is able to set current player to 1) it is then being set to 2, by the enclosed code.
code:
function switchCurrentPlayer()
{
if (currentPlayer == 1)
{
currentPlayer = 2;
}
else
{
currentPlayer = 1;
}
}
Would work.
Neater code to do the same thing:
code:
function switchCurrentPlayer() {
currentPlayer == 1 ? currentPlayer = 2: currentPlayer = 1;
}
syntax for that is like:
[if this bit is true] ? [do this] : [if not, do this];