xoligy Posted June 12, 2008 Share Posted June 12, 2008 Ok i found this on my hard disc when looking through a games script but im unsure whats happening can someone explain in laymens terms <?php for ($i=6; $i<15; $i++){ $commander=rand(1,3); if ($commander==3){ $commander=rand(0,10); if (!$commander)$commander=""; }else $commander=""; $race=rand(0,3); $jm=rand(0,100); /*for ($j=0; $j<$jm; $j++ ){ $unitProduction+=2; }*/ ?> Quote Link to comment https://forums.phpfreaks.com/topic/109874-think-this-is-the-right-section-someone-explain-whats-going-on/ Share on other sites More sharing options...
Renlok Posted June 12, 2008 Share Posted June 12, 2008 Ok i found this on my hard disc when looking through a games script but im unsure whats happening can someone explain in laymens terms <?php for ($i=6; $i<15; $i++){ $commander=rand(1,3); if ($commander==3){ $commander=rand(0,10); if (!$commander)$commander=""; }else $commander=""; $race=rand(0,3); $jm=rand(0,100); /*for ($j=0; $j<$jm; $j++ ){ $unitProduction+=2; }*/ ?> Not much it just looks like it gives random values to $jm, $race and $commander over and over again Quote Link to comment https://forums.phpfreaks.com/topic/109874-think-this-is-the-right-section-someone-explain-whats-going-on/#findComment-563847 Share on other sites More sharing options...
corbin Posted June 12, 2008 Share Posted June 12, 2008 Detailed explanation: <?php for ($i=6; $i<15; $i++){ //Start with value 6 for i, and run as long as i is less than 15, while incrementing by 1 each loop (so it should run 9 times) $commander=rand(1,3); //set commander to a random number between 1 and 3 (1,2,3) if($commander==3){ //if commander is 3 $commander=rand(0,10); if(!$commander)$commander=""; //if not commander set commander to a blank string //the not in this context means if commander is 0, since any other number would evaluate to true } //end if command is three else { //if commander is not three $commander=""; //set commander to a blank string } //end if commander is not three $race=rand(0,3); //set race to 0 1 2 or 3 $jm=rand(0,100); //set jm to a random number from 0 to 100 } //I added this closing brace.... dunno if you copied and pasted wrongly or what.... /* for ($j=0; $j<$jm; $j++ ){ $unitProduction+=2; } */ ?> Quote Link to comment https://forums.phpfreaks.com/topic/109874-think-this-is-the-right-section-someone-explain-whats-going-on/#findComment-564070 Share on other sites More sharing options...
btherl Posted June 13, 2008 Share Posted June 13, 2008 corbin covered the specifics quite well And renlok covered a mid-level view. From an overall viewpoint, the code appears incomplete. Is there more code within the for loop that you left out? If not, then I think it is unfinished code. After assigning the random values to $commander, $race and $jm, I would expect more code to use those values. But that code is missing. Quote Link to comment https://forums.phpfreaks.com/topic/109874-think-this-is-the-right-section-someone-explain-whats-going-on/#findComment-564448 Share on other sites More sharing options...
Daniel0 Posted June 13, 2008 Share Posted June 13, 2008 In other words, with commander there is a 29.7% chance that it will have a random number between 1 and 9 and 70.3% chance that it will be a blank string. Quote Link to comment https://forums.phpfreaks.com/topic/109874-think-this-is-the-right-section-someone-explain-whats-going-on/#findComment-564595 Share on other sites More sharing options...
xoligy Posted June 13, 2008 Author Share Posted June 13, 2008 Yea there was a little more code not much, it was more on creating a new accounts i just found it in a file of a game so wondered what the hell it did o.0 i thought it did something completely different tho so guess im going to have to figure out how i write what i want it to do then add it to the code im working on. Thanks for the detailed explanation btw! Quote Link to comment https://forums.phpfreaks.com/topic/109874-think-this-is-the-right-section-someone-explain-whats-going-on/#findComment-564646 Share on other sites More sharing options...
MasterACE14 Posted June 13, 2008 Share Posted June 13, 2008 looks similar to the King of Chaos clone Quote Link to comment https://forums.phpfreaks.com/topic/109874-think-this-is-the-right-section-someone-explain-whats-going-on/#findComment-565247 Share on other sites More sharing options...
.josh Posted June 26, 2008 Share Posted June 26, 2008 randomly found a php script on your hard drive huh... Quote Link to comment https://forums.phpfreaks.com/topic/109874-think-this-is-the-right-section-someone-explain-whats-going-on/#findComment-575515 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.