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;

}*/

?>


Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.