" . $stat . ""; return $str; } function swaplink($stat, $stats, $rerolled) { global $DEFSTATS; // PHP braindeadness, don't use foreach nested on the same array $copy = $DEFSTATS; $str = "Swap with: "; foreach ($DEFSTATS as $st) { if ($st == $stat) { continue; } $str .= "" . $st . " "; } return $str; } pre("Dnd roll example", array("no_sidebar" => true)); $reroll = (isset($_REQUEST["reroll"])); $rerolled = (isset($_REQUEST["rerolled"]) ? $_REQUEST["rerolled"] : false); $swap = (isset($_REQUEST["swap"])); $swapped = (isset($_REQUEST["swapped"]) ? $_REQUEST["swapped"] : false); if (!$reroll && !$swap) { do { $stats = genstats(); } while (!checkstats($stats)); } else { foreach ($DEFSTATS as $stat) { $stats[$stat] = $_REQUEST[$stat]; } if ($reroll) { $rerollstat = $_REQUEST["reroll"]; $newstat = rollstat(); $rerolled = $rerollstat . "|" . $stats[$rerollstat] . "|" . $newstat; $stats[$rerollstat] = max($stats[$rerollstat], $newstat); $rerolled .= "|" . $stats[$rerollstat]; } if ($swap) { $swapstat = $_REQUEST["swap"]; $with = $_REQUEST["with"]; $tmp = $stats[$swapstat]; $stats[$swapstat] = $stats[$with]; $stats[$with] = $tmp; } } print "\n"; if (!$rerolled) { print "\n"; } foreach ($DEFSTATS as $stat) { print "\n"; print " \n"; print " \n"; if (!$swapped) { print " \n"; } print "\n"; } print "
Click stat name to reroll
"; if (!$rerolled) { print rerollink($stat, $stats, $swapped); } else { print $stat; } print " " . $stats[$stat] . " (" . bonus($stats[$stat]) . ")" . swaplink($stat, $stats, $rerolled) . "
\n"; if ($rerolled) { list($stat, $old, $new, $max) = explode("|", $rerolled); print "

Rerolled " . $stat . ", got " . $new . ", old was " . $old . ", max " . $max . "

\n"; } if ($swapped) { list($stat1, $stat2) = explode("|", $swapped); print "

Swapped $stat1 for $stat2.

\n"; } print "

Roll again

\n"; post(); ?>