So I made a craps game with Javascript. And everything works properly, except I can’t get my rolls to appear on the screen in text. I got everything else to show up, but not the rolls.
Help would be appreciated.
This is the code I have.
//my variables
var win = 0; //total wins
var lose = 0; //total losses
var bet = 0; //starting bet until a bet button is pressed
var cash = 1000; //starting/current cash
var firstDie;
var secondDie;
var total;
var thirdDie;
var fourthDie;
var total2;
function Start () {
print (“Your bet sir”); //background intro
}
//betting buttons and rolls
function OnGUI () {
GUI.Box (Rect (10,10,100,150), “Your bet sir”); //betting box
if (GUI.Button (Rect (20,40,80,20), “50”)) //button to bet 50
{
bet = 50; //bet amount
}
if (GUI.Button (Rect (20,70,80,20), “100”)) //button to bet 100
{
bet = 100; //bet amount
}
if (GUI.Button (Rect (20,100,80,20), “500”)) //button to bet 500
{
bet = 500; //bet amount
}
if (GUI.Button (Rect (20,130,80,20), “Roll”)) //button to roll
{
RanNumGen();
}
GUI.BeginGroup(Rect(600,400,200,100)); //Group for labels in bottom corner
GUI.Label(Rect(0,0,200,20),“Your Money: $” +cash); //your total cash
GUI.Label(Rect(0,25,200,20),"Wins: "+win); //total wins
GUI.Label(Rect(0,50,200,20),"Losses: "+lose); //total losses
GUI.EndGroup();
GUI.Label(Rect(200,40,200,20),“Possible payoff is: $”+bet); //possible payoff from bet
}
function RanNumGen()
{
var firstDie = Random.Range(1, 6); //first random die roll
var secondDie = Random.Range(1, 6); //second random die roll
var total = firstDie + secondDie; //total of the die
print ("your roll is " + firstDie + " and " + secondDie + " for a total of " + total); //background totals
if (total == 7 || total == 11 || total == 2 || total == 12) //possible win/lose rolls
{
if (total == 7 || total == 11) //winning rolls
{
print (“you win”); //background print
win = win + 1; //adds 1 win to your win total
cash= cash + bet; //winning money
}
else //if you don’t roll a 7 or 11
{
print (" You Lose"); //background print
lose = lose + 1; //adds 1 lose to your lose total
}
}
else //if you don’t roll a 7, 11, 2, or 12
{
var thirdDie = Random.Range(1, 6); //third random die roll
var fourthDie = Random.Range(1, 6); //forth random die roll
var total2 = fourthDie + thirdDie; //total of these die
print ("your roll is " + thirdDie + " and " + fourthDie + " for a total of " + total2 ); //background totals
if (total2 == total) //if the second total equals the first total
{
print (“you win”); //background print
win = win +1; //adds 1 win to your win total
cash = cash + bet; //winning money
}
else //if the totals don’t match
{
print (“you lose”); //background print
lose = lose + 1; //adds 1 lose to your lose total
cash = cash - bet; //if you lose you win no cash
}
}
print ("your win / loss is " + win + “/” + lose ); //your win/lose totals
print (“your total cash” + cash); //your total money so far
}