Jump to content

Think this is the right section - Someone explain whats going on?


xoligy

Recommended Posts

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;

}*/

?>


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

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;
}
*/
?>

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.

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!

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.