我已经有一段时间这个问题了,最后我将其范围缩小了(我认为)。
我试图对收入设置一个限制,该限制是$ storagecap每个$仓库=到500 $ storagecap。在我向您展示代码之前,我将告诉您我的问题。
它显示了您目前拥有2个仓库的限额的示例,它说我的限额为1000,但它使我的收入停止在499(我将其设置为等于0个仓库),因此显示499/1000。 Cron_turn将您的收入添加到您的帐户中。
我不知道为什么知道$ storagecap为1000时为什么会在499停下来。
storagecap.php
<?php
$warehouse = $building['warehouse'];
if ($warehouse == 1) {
$storagecap = 500;
}elseif($warehouse == 2) {
$storagecap = 1000;
}elseif($warehouse == 3) {
$storagecap = 1500;
}elseif($warehouse == 4) {
$storagecap = 2000;
}elseif($warehouse == 5) {
$storagecap = 2500;
}elseif($warehouse == 6) {
$storagecap = 3000;
}elseif($warehouse == 7) {
$storagecap = 3500;
}elseif($warehouse == 8) {
$storagecap = 4000;
}elseif($warehouse == 9) {
$storagecap = 4500;
}elseif($warehouse == 10) {
$storagecap = 5000;
}elseif($warehouse == 11) {
$storagecap = 5500;
}elseif($warehouse == 12) {
$storagecap = 6000;
}elseif($warehouse == 13) {
$storagecap = 6500;
}elseif($warehouse == 14) {
$storagecap = 7000;
}elseif($warehouse == 15) {
$storagecap = 7500;
}elseif($warehouse == 16) {
$storagecap = 8000;
}elseif($warehouse == 17) {
$storagecap = 8500;
}elseif($warehouse == 18) {
$storagecap = 9000;
}elseif($warehouse == 19) {
$storagecap = 9500;
}elseif($warehouse == 20) {
$storagecap = 10000;
}elseif($warehouse == 0) {
$storagecap = 499;
}else{
$storagecap = 10;
}
?>
* cron_turn.php *
<?php
include("functions.php");
connect();
include("safe.php");
include("storagecap.php");
$get_users = mysql_query("SELECT * FROM `stats`") or die(mysql_error());
while($user = mysql_fetch_assoc($get_users)) {
//Get
$gold = $user["gold"];
$food = $user["food"];
$energy = $user["energy"];
//Increment
$gold += $user["income"];
$food += $user["farming"];
$energy += 5;
//Verify and correct
if ($energy > 100) {
$energy = 100;
};
if ($gold > $storagecap) {
$gold = $storagecap;
};
if ($food > $storagecap) {
$food = $storagecap;
};
//Submit
$update = mysql_query("UPDATE `stats` SET
`gold`= '".$gold."',
`food`= '".$food."',
`energy`= '".$energy."' WHERE `id`='".$user['id']."'") or die(mysql_error());
}
?>
最佳答案
在将值分配给$building['warehouse']
之前,要先包含storagecap.php文件。由于要在if语句中将null与int进行比较,因此0表示为true。将包含向下移动到您具有$building['warehouse']
值的点