xoligy Posted May 19, 2008 Share Posted May 19, 2008 ok should be pretty simple (i think) the code below should display "???" if the person doesn't have enough spy skill to see everything but for somereason it sometimes puts "0" how would i go about fixing it? function spiedValue($value,$difPerc){ $value=(rand(($difPerc-100),$difPerc)>10)?$value:"???"; return $value; I believe thats all the code you need from the page but i can get the other stuff if needed Link to comment https://forums.phpfreaks.com/topic/106316-function-not-returning-right-value/ Share on other sites More sharing options...
micah1701 Posted May 19, 2008 Share Posted May 19, 2008 what are the parameters you are sending the times that it returns "0" ? Link to comment https://forums.phpfreaks.com/topic/106316-function-not-returning-right-value/#findComment-544855 Share on other sites More sharing options...
xoligy Posted May 19, 2008 Author Share Posted May 19, 2008 eh what do you mean? I dont know where the "0" is coming from here is the rest of the php for spy $defender=getUserDetails($cgi['id']); $time=time(); //echo ($atacker->currentSpySkill+1).";;".$defender->currentSpySkill."##<br>"; //if (($atacker->currentSpySkill+1)<$defender->currentSpySkill){ $tSpies=$atacker->spies; $atacker->spies=$atacker->spies-$cgi['numspies']; $spyStrength=getCovertAction($atacker); $atacker->spies=$tSpies; $spyDefStrength=getCovertAction($defender); if ($spyStrength<($spyDefStrength-100)){ $isSuccess=0; $fields=" `time` , `spies`, `isSuccess`"; $values="'$time' , '".$cgi['numspies']."', '$isSuccess'"; updateUser($atacker->ID, " spies=spies-{$cgi['numspies']} "); }else{ $isSuccess=1; $spies=$cgi['numspies']; $race=$defender->race; //$atacker->spies=$cgi['numspies']; $dif=$spyStrength-$spyDefStrength; if ($dif>100)$dif=100; $dif+=100; $difPerc=$dif/2; // echo "--$difPerc--<br>"; $trainedAttackSold=spiedValue($defender->trainedAttackSold,$difPerc); $trainedAttackMerc=spiedValue($defender->trainedAttackMerc,$difPerc); $trainedDefSold=spiedValue($defender->trainedDefSold,$difPerc); $trainedDefMerc=spiedValue($defender->trainedDefMerc,$difPerc); $untrainedMerc=spiedValue($defender->untrainedMerc,$difPerc); $untrainedSold=spiedValue($defender->untrainedSold,$difPerc); $strikeAction=getStrikeAction($defender); $strikeAction=spiedValue($strikeAction,$difPerc); $defenceAction=getDefenseAction($defender); $defenceAction=spiedValue($defenceAction,$difPerc); $covertSkill=spiedValue($defender->currentSpySkill ,$difPerc); $covertOperatives=spiedValue($defender->spies ,$difPerc); $siegeLevel=spiedValue($defender->siegeLevel,$difPerc); $atackTurns=spiedValue($defender->attackTurns,$difPerc); $unitProduction=spiedValue($defender->currentUnitProduction ,$difPerc); /* $weapons $types $quantities $strengths $allStrengths */ $weapon1=getUserAllWeapon($defender); for ($i=0;$i<count($weapon1);$i++){ if (!spiedValue(0,$difPerc)){ $weapons.=spiedValue($weapon1[$i]->weaponID,$difPerc).";"; $types.=spiedValue($weapon1[$i]->isAtack ,$difPerc).";"; $types2.=$weapon1[$i]->isAtack.";"; $quantities.=spiedValue($weapon1[$i]->weaponCount ,$difPerc).";"; $strengths.=spiedValue($weapon1[$i]->weaponStrength ,$difPerc).";"; //$allStrengths.=spiedValue($weapon1[$i]->weaponID,$difPerc).";"; if ($weapon1[$i]->isAtack){ $tS=$conf["race"][$defender->race]["weapon"][$weapon1[$i]->weaponID]["strength"]; }else{ $tS=$conf["race"][$defender->race]["defenseweapon"][$weapon1[$i]->weaponID]["strength"]; } $allStrengths.=spiedValue($tS,$difPerc).";"; } } if (strlen($weapons)){ $weapons=substr($weapons,0,strlen($weapons)-1); $types=substr($types,0,strlen($types)-1); $types2=substr($types2,0,strlen($types2)-1); $quantities=substr($quantities,0,strlen($quantities)-1); $strengths=substr($strengths,0,strlen($strengths)-1); $allStrengths=substr($allStrengths,0,strlen($allStrengths)-1); } $trainedAttackSold =$defender->trainedAttackSold; $fields="`spyStrength`, `spyDefStrength`, `trainedAttackSold`, `trainedAttackMerc`, `trainedDefSold`, `trainedDefMerc`, `untrainedMerc`, `untrainedSold`, `strikeAction` , `defenceAction`, `covertSkill` , `covertOperatives`, `siegeLevel` , `atackTurns` , `unitProduction` , `weapons`, `types`, `types2` , `quantities`, `strengths` , `allStrengths`, `time` , `spies`, `isSuccess`, `race`"; $values="'$spyStrength', '$spyDefStrength', '$trainedAttackSold', '$trainedAttackMerc', '$trainedDefSold', '$trainedDefMerc', '$untrainedMerc', '$untrainedSold', '$strikeAction', '$defenceAction', '$covertSkill', '$covertOperatives', '$siegeLevel' , '$atackTurns' , '$unitProduction' , '$weapons', '$types', '$types2' , '$quantities', '$strengths' ,'$allStrengths', '$time' , '$spies', '$isSuccess', '$race'"; } //echo $fields."<br>"; //echo $values; //return; addSpy($atacker->ID,$defender->ID,$fields,$values); //return; $spy=getSpyByUser1User2AndTime($atacker->ID,$defender->ID,$time, " ID "); header("Location: spylog.php?id={$spy->ID}"); }else{$strErr="You should enter the number of spies to send.";} } If you look at this image you'll see sometimes it works other times it dont :/ http://i4.photobucket.com/albums/y126/liamsidley/Screenshot-3.png Link to comment https://forums.phpfreaks.com/topic/106316-function-not-returning-right-value/#findComment-544874 Share on other sites More sharing options...
xoligy Posted May 20, 2008 Author Share Posted May 20, 2008 no clues? Link to comment https://forums.phpfreaks.com/topic/106316-function-not-returning-right-value/#findComment-545553 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.