Coding a Gamble event with little success.

So I've recently been learning a bit of coding, and while testing things out, I thought to give a Gamble event a whirl. I have an Input Number event set up, where the player inputs a number for how much gold they wanna spend. Once that number is entered, I am trying to do a conditional branch to check if the player has less than that amount. If so, the player is denied the gamble and the event ends. I thought the best way to check it was with a script, having it check if the variable was greater than the game data for gold. However, while testing, I kept getting a couple different errors with my code the moment it went to run the if...else event. Usually a "unexpected token var" error. When I removed the "if" part in the script, it gave me an "unexpected token >" error. I've been trying different things and I'm just confused and wanting help at this point haha. Testing with the proper amount of gold yields the same error, so it's definitely a problem with the execution of the "if" event.

Spoiler: The Event
1660590773422.png
thats because "if var token >" is already an issue.
you could do rather.

Variable x = gold (default for control variables.

than if: $gameVariables.value(x) > y // you value here or take the default settings
do you thing
else
you dont have enough gold
end

this is the most basic part for checking gold though.
thats because "if var token >" is already an issue.
you could do rather.

Variable x = gold (default for control variables.

than if: $gameVariables.value(x) > y // you value here or take the default settings
do you thing
else
you dont have enough gold
end

this is the most basic part for checking gold though.
Okay so I want to make a separate variable and attach it to the game data Gold. So this would be the code I wanna use?
Spoiler: New Code
1660592627463.png
Edit: This was my reply to your original post before the conversation with @ShadowDragon took place. However I still believe it adresses the problem with your second approach.

You don't need a script. You can set a variable to the party's gold via event commands and then just compare both variables in the conditional branch event command. This would be my recommended approach for your specific scenario.

Now on to some education:
If you would be writing javascript in another context you would indeed put:
JavaScript:
if (someStatement) {//either true or false
    //do something
}
else { //optional
    //do something else
}
However since you have put your script already into a conditional branch event command this is already taken care of by the RPG Maker engine. You only need to supply the someStatement. So the if actually is wrong and does indeed mess up your code.

But it doesn't stop there. With var you are declaring a new variable in a global scope. In your case that would be a variable called Gamble_Money. While this is valid javascript, it is not what you want. In addition this leads the interpreter to see > $gameData.gold as a second statement. And here the > is indeed an invalid way to start a new statement.
To access an already existing variable you need to simply type its name, without the var prefix.

Next, game variables do not exist simply "floating around" in the global scope. They exist in an array in the $gameVariables object. To read the value of a game variable you will need the script call:
JavaScript:
$gameVariables.value(variableId);

Also there exists no "$gameData" object. If you want to check the existing objects and their properties and functions I recommend takeing a look at https://kinoar.github.io/rmmv-doc-web/globals.html

In your case you would see that to find out about the gold the player has you can call:
JavaScript:
$gameParty.gold();
Edit: This was my reply to your original post before the conversation with @ShadowDragon took place. However I still believe it adresses the problem with your second approach.

You don't need a script. You can set a variable to the party's gold via event commands and then just compare both variables in the conditional branch event command. This would be my recommended approach for your specific scenario.

Now on to some education:
If you would be writing javascript in another context you would indeed put:
JavaScript:
if (someStatement) {//either true or false
    //do something
}
else { //optional
    //do something else
}
However since you have put your script already into a conditional branch event command this is already taken care of by the RPG Maker engine. You only need to supply the someStatement. So the if actually is wrong and does indeed mess up your code.

But it doesn't stop there. With var you are declaring a new variable in a global scope. In your case that would be a variable called Gamble_Money. While this is valid javascript, it is not what you want. In addition this leads the interpreter to see > $gameData.gold as a second statement. And here the > is indeed an invalid way to start a new statement.
To access an already existing variable you need to simply type its name, without the var prefix.

Next, game variables do not exist simply "floating around" in the global scope. They exist in an array in the $gameVariables object. To read the value of a game variable you will need the script call:
JavaScript:
$gameVariables.value(variableId);

Also there exists no "$gameData" object. If you want to check the existing objects and their properties and functions I recommend takeing a look at https://kinoar.github.io/rmmv-doc-web/globals.html

In your case you would see that to find out about the gold the player has you can call:
JavaScript:
$gameParty.gold();
Oh wow, this was honestly really informative! Thank you so much for this. I used the events above to try it and it works so far! I'll be continuing to build on this event and hopefully not run into more issues lol Thank you both for the help and support!

Original thread: https://forums.rpgmakerweb.com/threads/coding-a-gamble-event-with-little-success.150466/