Request a Tut?

Post all your tuts or request for tuts here.
Post Reply
User avatar
Xaos
Posts: 940
Joined: Wed Jan 11, 2012 4:01 am

Request a Tut?

Post 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.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Request a Tut?

Post 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?
The indelible lord of tl;dr
User avatar
Xaos
Posts: 940
Joined: Wed Jan 11, 2012 4:01 am

Re: Request a Tut?

Post 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.
ronislegend
Posts: 17
Joined: Mon Sep 24, 2012 8:33 pm

Re: Request a Tut?

Post 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.
Post Reply

Return to “Tutorials”