所以我試圖在一個假的RPG中爲stat增長製作一個數組。它看起來像這樣。php;在循環中添加一個多維數組的值
// base array
// $base: starting base stats
// $growth: growth rate per rng
$growths = array(
'HP' => array (70 => 20),
'STR' => array (50 => 7),
'MAG' => array (35 => 2),
'SKL' => array (45 => 6),
'SPD' => array (50 => 8),
'LCK' => array (55 => 5),
'DEF' => array (45 => 6),
'RES' => array (15 => 4),
);
//rng calculator
for ($x = 0; $x <= 20; $x++) {
foreach ($growths as $stat_name => $info) {
$roll = rand(0,100);
foreach ($info as $growth => $base) {
if ($roll <= $growth) {
$info[$growth] = ++$base;
print "(UP!) ";
}
echo "$stat_name: $base<br/ >";
}
}
}
我唯一的問題是,rng calculator
後的新$base
值拒絕原始數組中存儲。我做錯了什麼,或者我只是需要從頭開始重建數組並嘗試其他的東西?任何幫助,將不勝感激!
難道你不想'滾(1,100)'? –
不確定 - roll()和rand()之間有什麼區別? – EM6
哎呀抱歉,是的,我的意思是「rand(1,100)'。這看起來像紙筆RPG,我認爲這是一個百分比骰子滾動,通常不會爲零。 –