Page 1 of 1

Request a Tut?

Posted: Wed Aug 01, 2012 4:51 am
by Xaos
If i could........Could I please request a tutorial that shows me to make a button that will roll a dice, keep the added total, and allow you to roll again? Preferably all in the same page, and if POSSIBLE, without having a database to the send the info too. What i'm trying to do is make a dice football game where you click the roll button, it rolls, gives you the result of the play and loss or gaining of yardage, and allows you to roll again (obviously) staying at the same place on the field.

Re: Request a Tut?

Posted: Wed Aug 01, 2012 5:45 am
by Jackolantern
Considering you are talking about databases, I am assuming you are talking about PHP, right? And also, what is your level of experience?

Re: Request a Tut?

Posted: Wed Aug 01, 2012 5:54 am
by Xaos
Oh yeah, I am talking about PHP, haha, sorry for not mentioning. and my experience level is so-so...... i've seen some of halls' tuts, looked at some other tuts, etc.

Re: Request a Tut?

Posted: Tue Oct 16, 2012 3:08 am
by ronislegend
This would be easier done with JS rather than PHP, you can store each dice roll in a javascript array. If you want to save the rolls, serialize the array and store in a cookie.

So here's what you want to do, create a function called dice_roll()

Code: Select all

var rolls = new Array();
var dice_roll = function() {
var roll = Math.floor((Math.random()*6)+1);
rolls[] = roll;
return roll;
}
Then you can just create the button that triggers the JS function

Code: Select all

<a href="javascript:dice_roll();" class="btn">Roll dice!</a>
You can further advance the function to show what the user rolls, and past rolls by appending the result to div's or whatever you want.