Javascript syntax errors with basic expressions

The error I get is

Scripts/Gamble.js(17,23): BCE0044: expecting ), found ‘=’.

if I double up that equals sign I get

Scripts/Gamble.js(13,18): BCE0034: Expressions in statements must only be executed for their side-effects.

var balance : float = 0.0;
var payOut : float = 0.0;
var betAmount : float = 100.0;
var profitOnWin : float = 0.0;
var rollUnderToWin : float = 0.0;
var diceNumber : float = 50.0;
var totalWin : float = 0.0;
public var winChance : float = 0.0;

function FixedUpdate (){
	totalWin == payOut*betAmount;
	profitOnWin == totalWin-betAmount;
	rollUnderToWin == winChance;
	
	if (winChance == 50.0){
	 	payOut == 1.98;
	 	}
	if (winChance == 25.0){
	 	payOut == 3.96;
	 	}
	if (winChance == 10.0){
	 	payOut == 9.9;
	 	}
	 //
	//if button press, call function DiceRoll
}

function DiceRoll (){
	diceNumber == Random.Range(0.0,100.0);
	if (diceNumber <= winChance){
		GUI.Label(screenRect, "You Win!");
		//add profit to balance
		balance+=profitOnWin;
		}
	if (diceNumber >= winChance){
		GUI.Label(screenRect, "You Lose!");
		//subtract betAmount from balance
		balance-=betAmount;
		}
}

I have no idea what I’m doing wrong with the syntax here, I’ve been making adjustments for hours and can’t get it.

Hello,

There is one key thing wrong in your script, but before I get to that, there are a couple other things I should mention:

The indentation level of open { and closed } should be the same:

if (comparison) {
}
//NOT
if (comparison) {
    }

Absolutely everyone is in agreement, that you should leave a space between ) and {:

if (comparison) {
//OR
if ( comparison ) {
//BUT NEVER
if(comparison){

Now onto the actual problem:

In UnityScript, just like in C#, there are different types of operators, such as x.y or < etc. These are all about using special syntax to achieve certain things.

There are primary:

//Member access with the "." operator
x.y
//Invoke methods
f(x)
//Type casting
x as y
//increasing using the increment operator
x++
//Getting the size of the object
sizeof(x)

There are the Unary:

//Positive
+x
//Negative
-x
//Not
!x
//Increment
++x
//Decrement
--x

There are the multiplicative:

//Multiply
x*y
//Divide
x/y
//Mod
x%y

Additive:

//Addition
x + y
//Subtraction
x - y

Shift:

//Right Shift
x >> y
//Left Shift
x << y

Relation:

//Larger Than
x > y
//Smaller Than
x < y
//With equals
x >= y
x <= y
//Type checking
x is y

Equality:

//Are Equal
x == y
//Are Not Equal
x != y

Logical:

//And
x & y
//Or
x | y
//XOr
x ^ y

Conditional:

//And
x && y
//Or
x || y

Assignment:

//Assign to
x = y
//Add do
x += y
//Subtract from
x -= y
//Multiply py
x *= y
//Divide by
x /= y
//lots more

All of this information can be found here and although it’s a C# reference, UnityScript has most of the basic operators too.

Now lets look at the line where your error occurs and lets see which operator you are using:

rollUnderToWin == winChance;
 
if (winChance == 50.0){

So the first line you are doing a comparison between rollUnderToWin and winChance and then later you do a comparison between winChance and 50.0 to check if they are equal. Why are you doing a comparison in the first one? Does that make any sense?

Lets look at what happens when we use a single =:

rollUnderToWin = winChance;
 
if (winChance = 50.0){

First we assign winChance to rollUnderToWin and then we check, we assign (WTF) winChance the value of 50.0… That doesn’t make any sense does it?

I think from this you should be able to figure out what you need to do to make it work.

Hope this helps,
Benproductions1

You would never use == when you are assigning values to a variable; that’s only for comparing two values. == for comparison, = for assignment.