Closed (fixed)
Project:
Computed Field
Version:
5.x-1.2
Component:
User interface
Priority:
Normal
Category:
Support request
Assigned:
Reporter:
Created:
27 Nov 2007 at 17:07 UTC
Updated:
5 May 2008 at 00:15 UTC
I'm trying to create a random die roller, and I've got the computed section worked out, but I can't get the results to display multiples.
For example: The user enters the number of sides on the die (such as 6 for a normal cube die), then the number of rolls. The computed section iterates a for loop with the number of rolls as the endpoint. Each roll is randomized using the number of sides field.
I tried a foreach loop with the following:
foreach ($node_field as $value) {
$display = $node_field_item['value'];
}
But I get an error that I've used an invalid argument in the foreach statement.
Is there an easy way to display multiple results?
Here is my computed code:
for ($n = 0; $n <= ($node->field_rolls[0]['value'] - 1); $n++) {
$node_field[$n]['value'] = rand(1, $node->field_sides[0]['value']);
}
Any help is appreciated!
Comments
Comment #1
Steel Rat commentedOk, I've scrapped what I was trying to do previously, and went with a code snippet for rolling dice someone else posted.
I had it working very briefly, but then the results all started returning 0.
Here's my computed code:
And the display code is the default.
The expression field_sides field expects a format of xdy where x = the number of rolls and y = the number of sides on the die.
Any ideas?
Comment #2
Steel Rat commentedFor some reason the $rolls[$i] value was always returning zero. I changed it to just $rolls and it works fine now. It just means the user can't enter multiple rolls, which I can deal with until I figure out something better.
Comment #3
Steel Rat commentedOne thing I need to be able to do here as well is break out each die roll and have it displayed. Right now all I get is a total.
Comment #4
Steel Rat commentedWell, I figured out how to get the individual rolls, but then the result display is messed up when using a view. I don't suppose there's a way to make a hidden field to store the individual die rolls which I can then display as needed.
Comment #5
Justin Freeman commentedSee this example, http://drupal.org/node/249907
Comment #6
Steel Rat commentedThanks,