Making a monopoly dice system

Greetings Everyone
How are you all today? good I hope =)
this is my first post here so ill try to explain the best i can :smile:

here’s what I’m trying to do, I’m working on a monopoly game for my school’s final project and so far things are going smooth, but I’m having a little problem on the dice stytem

so far this is my code:

function Update () {
var dice1:int = Random.Range(1, 7);
var dice2:int = Random.Range(1, 7);
var diceResult = dice1 + dice2;
var playTimes:int = 0;
var playAgainTimes:int = 0;
var playAgain=false;

if(Input.GetButtonUp(“Jump”))
{
playTimes = diceResult;
Debug.Log(playTimes);

if(dice1 == dice2){
playAgainTimes +=1;
Debug.Log("play again = " + playAgainTimes);

if(playAgainTimes == 3){
Debug.Log(“Jail Time”);
}else if(dice1 != dice2){
playAgainTimes=0;
Debug.Log("the number is " + playAgainTimes);
}

}
}
}

well so far i managed to do a random number generator and checking if the number of the dices where the same, and that would add a turn, if the turns where equal to 3 then the piece would go to jail, but the problem is, every time the dices are equal to each other more than 2 times , the var playAgainTimes is always equals to 1.

here’s a picture of it:

so what’s wrong?
I’m sorry but I’m still a little fresh on uniscript, i know a bit of javascript(still learning ^^)

I thank you all in advance for your time and thank you for helping me ^^

function Update () {
var dice1:int = Random.Range(1, 7);
var dice2:int = Random.Range(1, 7);
var diceResult = dice1 + dice2;
var playTimes:int = 0;
var playAgainTimes:int = 0;
var playAgain=false;

should be

var dice1:int = Random.Range(1, 7);
var dice2:int = Random.Range(1, 7);
var diceResult = dice1 + dice2;
var playTimes:int = 0;
var playAgainTimes:int = 0;
var playAgain=false;
function Update () {

Edit: You may find you have to declare the variable outside of Update, then set the values inside the Start() function.

thank you for your reply wccrawford ^^

ummmmmm i see, but why use the start function? (sorry for the noob question)

once again I thank you all in advance for your time and for helping me ^^

Some languages won’t let you write code outside the function, so the ones that are setting variables to other variables might have an issue. Or they might not. I haven’t used JS enough in Unity to be sure. If it works as-is, there’s no need to worry. :slight_smile:

ummmmmm i see, well i’ll keep trying, thank you once again for your reply ^^