到目前为止,我试图为游戏制作一个简单的战斗脚本,但处理战斗的这段代码总会返回以下错误:
等等......我希望有人能发现问题吗?注意:使用未定义的常量ime - 在第17行的C:\ Program Files(x86)\ wamp \ www \ php \ gozd.php中假定为'ime'
注意:使用未定义的常量napad - 在第18行的C:\ Program Files(x86)\ wamp \ www \ php \ gozd.php中假定为'napad'
if($_POST['action'] == 'Napadi') {
$igralec_ime = $_SESSION['username'];
$igralec = array (
ime => $igralec_ime,
napad => prikazi_stat('ofe',$igralec_ime),
obramba => prikazi_stat('def',$igralec_ime),
curhp => prikazi_stat('curhp',$igralec_ime)
);
$monster_ime = $_POST['monster'];
$monster = array (
ime => $monster_ime,
napad => prikazi_monster_stat('atk',$monster_ime),
obramba => prikazi_monster_stat('def',$monster_ime),
curhp => prikazi_monster_stat('maxhp',$monster_ime)
);
$combat = array();
$turns = 0;
while($igralec['curhp'] > 0 && $monster['curhp'] > 0) {
if($turns % 2 != 0) {
$napadalec = &$monster;
$branilec = &$igralec; }
else {
$napadalec = &$igralec;
$branilec = &$monster; }
$damage = 0;
if($napadalec['napad'] > $branilec['obramba']) {
$damage = $napadalec['napad'] - $branilec['obramba']; }
$branilec['curhp'] -= $damage;
$combat[$turns] = array(
napadalec => $napadalec['ime'],
branilec => $branilec['ime'],
damage => $damage
);
$turns++; }
update_stat('curhp',$igralec_ime,$igralec['curhp']);
if($igralec['curhp'] > 0) {
update_stat('cek',$igralec_ime,prikazi_stat('cek',$igralec_ime)+ prikazi_monster_stat('cek',$monster_ime));
$zmaga = 1;
$cekini = prikazi_monster_stat('cek',$monster_ime); }
else {
$zguba = 1; } }
答案 0 :(得分:3)
您的数组键未引用。代码应为:
"ime" => $igralec_ime,
"napad" => prikazi_stat('ofe',$igralec_ime),
"obramba" => prikazi_stat('def',$igralec_ime),
"curhp" => prikazi_stat('curhp',$igralec_ime)
然而,PHP正在“帮助”你说“哎呀,我不知道ime
是什么 - 程序员可能意味着"ime"
(带引号),所以让我假装这就是我刚看到“。
非常不幸的是,今天的PHP表现得像这样(原因是历史性的,最好的不为人知),但至少它有道德通知可能有些不妥。