Evermore Posted August 26, 2011 Share Posted August 26, 2011 I am not a very good PHP programmer, and I got a project to "work" on. I need help writing a Dice Roll Function. This is how I'm supposed to do the two functions: New Function: dice_roll (int sides) - $ returns a random number of how many sided the dice is, between 1 and the $. New Function: dice_roll_str (string dicestr) - A string describing the dice [0-9] + d [0-9 ]+[+-][ 0-9] + size (d <number_of_dices> <number_of_sides> [+-][modifying_value]) - For example if I call the function with "3d6-3", this means: we throw 3 times with a 6-sided dice, add it up, then subtract 3-t. - The function is to return a false value on error - Possible errors: - Minimum number of of sides of the dice is 2 the maximum is 24 - A minimum number of dices 1 the maximum is 8 - The result should always be a positive number, which is not greater than twice of the result we got. I've already done the first function. This is my code: function dice_roll($sides_num) { $rand_num = rand(1, $sides_num); return $rand_num; } I'm not sure it correct. It is the second function that I don't know how to do. Please, if you can help I'd be really grateful. If you can please put explanations on how the code works. Thank you so much, Evermore Quote Link to comment https://forums.phpfreaks.com/topic/245753-php-dice-roll-function-help/ Share on other sites More sharing options...
Muddy_Funster Posted August 26, 2011 Share Posted August 26, 2011 OK, firstly - the plural of dice is die Secondly - this looks more suited to the freelance section, as you are effectivly asking somone to write a self contained pice of code for you, not fix a problem with some existing code of your own. However, could you clear up the formaula: "- A string describing the dice [0-9] + d [0-9 ]+[+-][ 0-9] + size (d <number_of_dices> <number_of_sides> [+-][modifying_value])" as to what d is refferencing and what dictates the <number_of_die> and <modifying_value>? And also what do you meen by " - The result should always be a positive number, which is not greater than twice of the result we got." Quote Link to comment https://forums.phpfreaks.com/topic/245753-php-dice-roll-function-help/#findComment-1262217 Share on other sites More sharing options...
WebStyles Posted August 26, 2011 Share Posted August 26, 2011 Very basic example <?php // value for each side (using colors and the 'standard' 6 sides) $values = array('BROWN','PINK','YELLOW','BLUE','RED','GREEN'); // random value $number = rand(0,sizeof($values)-1); // show result; echo $values[$number]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/245753-php-dice-roll-function-help/#findComment-1262218 Share on other sites More sharing options...
Pikachu2000 Posted August 26, 2011 Share Posted August 26, 2011 OK, firstly - the plural of dice is die Actually, dice is the plural. Die is the singular. Quote Link to comment https://forums.phpfreaks.com/topic/245753-php-dice-roll-function-help/#findComment-1262265 Share on other sites More sharing options...
AyKay47 Posted August 26, 2011 Share Posted August 26, 2011 OK, firstly - the plural of dice is die Actually, dice is the plural. Die is the singular. he got you there.. Quote Link to comment https://forums.phpfreaks.com/topic/245753-php-dice-roll-function-help/#findComment-1262267 Share on other sites More sharing options...
WebStyles Posted August 26, 2011 Share Posted August 26, 2011 Actually, dice is the plural. Die is the singular. lol if you're wondering, in portuguese it's DADO and DADOS Quote Link to comment https://forums.phpfreaks.com/topic/245753-php-dice-roll-function-help/#findComment-1262269 Share on other sites More sharing options...
Pikachu2000 Posted August 26, 2011 Share Posted August 26, 2011 Same in Spanish, IIRC. Quote Link to comment https://forums.phpfreaks.com/topic/245753-php-dice-roll-function-help/#findComment-1262271 Share on other sites More sharing options...
WebStyles Posted August 26, 2011 Share Posted August 26, 2011 ..oh, and they all have 6 sides... never seen one with 24. Quote Link to comment https://forums.phpfreaks.com/topic/245753-php-dice-roll-function-help/#findComment-1262273 Share on other sites More sharing options...
cssfreakie Posted August 26, 2011 Share Posted August 26, 2011 Actually, dice is the plural. Die is the singular. lol if you're wondering, in portuguese it's DADO and DADOS if you guys are wondering dice in Swahili is kete.. Quote Link to comment https://forums.phpfreaks.com/topic/245753-php-dice-roll-function-help/#findComment-1262275 Share on other sites More sharing options...
WebStyles Posted August 26, 2011 Share Posted August 26, 2011 if you guys are wondering dice in Swahili is kete yet nobody know what it is in Esperanto, which is supposed to be the f'ing universal language. Quote Link to comment https://forums.phpfreaks.com/topic/245753-php-dice-roll-function-help/#findComment-1262277 Share on other sites More sharing options...
Evermore Posted August 30, 2011 Author Share Posted August 30, 2011 ..oh, and they all have 6 sides... never seen one with 24. Actually, there is. Type in 24 sided dice into Google Images and they will come out. Quote Link to comment https://forums.phpfreaks.com/topic/245753-php-dice-roll-function-help/#findComment-1263424 Share on other sites More sharing options...
Muddy_Funster Posted August 30, 2011 Share Posted August 30, 2011 ..oh, and they all have 6 sides... never seen one with 24. You never played AD&D then ....ahh, the good old days. Quote Link to comment https://forums.phpfreaks.com/topic/245753-php-dice-roll-function-help/#findComment-1263429 Share on other sites More sharing options...
WebStyles Posted August 30, 2011 Share Posted August 30, 2011 had to look that up... Advanced Dungeons and Dragons? lol. Nope, never played it. Man I'm from the days of the spectrum, I used to play Chuckie Egg and Manic Miner... No dice involved, just mad skills! Quote Link to comment https://forums.phpfreaks.com/topic/245753-php-dice-roll-function-help/#findComment-1263432 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.