deadlyp99 Posted August 14, 2009 Share Posted August 14, 2009 So hello all. I'm creating a script taht logically defines a map: A shortened version of it is: [-1,-1][-1,0][-1,1] [0, -1][ 0,0 ][0, 1] [1,-1 ][1, 0 ][1, 1] I've got my output set up to display like this: StartID: 1 X: -5 Y: -5 MapType: 0 OasisType: 8 StartID: 2 X: -5 Y: -4 MapType: 6 OasisType: 0 StartID: 3 X: -5 Y: -3 MapType: 1 OasisType: 0 StartID: 4 X: -5 Y: -2 MapType: 7 OasisType: 0 StartID: 5 X: -5 Y: -1 MapType: 7 OasisType: 0 StartID: 6 X: -5 Y: 0 MapType: 3 OasisType: 0 StartID: 7 X: -5 Y: 1 MapType: 6 OasisType: 0 StartID: 8 X: -5 Y: 2 MapType: 7 OasisType: 0 StartID: 9 X: -5 Y: 3 MapType: 1 OasisType: 0 StartID: 10 X: -5 Y: 4 MapType: 1 OasisType: 0 StartID: 11 X: -5 Y: 5 MapType: 3 OasisType: 0 However, going on a -x,-x to x,x format, I'm finding only one row is being generated, which is -x,-x to -x,x I am pretty sure this is a problem in my for loop, but I'm not entirely sure what, so i'll post my code in hopes someone can find the error in my logic. I really appreciate anyone who can provide insight to what the problem is. Thanks in advanced, and have a great day <?php $StartID = 0; $StartX = -5; $StartY = -5; $EndX = 5; $EndY = 5; $MapType = array('1','2','3','4','5','6','7','8','9','10','11','12'); $OasisType = array('1','2','3','4','5','6','7','8'); $ThePool = array( '1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1', '1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1', '1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1', '1','1', '2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2', '3','3','3','3','3','3','3','3','3','3','3','3','3','3','3','3', '4','4','4','4','4','4','4','4','4','4','4','4','4','4','4','4', '5','5','5','5','5','5','5','5','5','5','5','5','5','5','5','5', '6','6','6','6','6','6','6','6','6','6','6','6','6','6','6','6', '7','7','7','7','7','7','7','7','7','7','7','7','7','7','7','7', '8','8','8','8','8','8', '9','9','9','9','9','9', '10','10','10','10','10','10', '11','11', '12','12', '1b','1b','1b', '2b','2b', '3b','3b','3b', '4b','4b', '5b','5b','5b', '6b','6b', '7b','7b', '8b','8b','8b','8b' ); for ($StartX;$StartX<=$EndX;$StartX++) { for ($StartY;$StartY<=$EndY;$StartY++) { $RandomChoice = $ThePool[array_rand($ThePool)]; if (is_numeric($RandomChoice)) { $MapType = $RandomChoice; $OasisType = '0'; } else { $MapType = '0'; $OasisType = ExtractOasisType($RandomChoice); } $StartID += 1; print("StartID: ".$StartID." X: ".$StartX." Y: ".$StartY." MapType: ".$MapType." OasisType: ".$OasisType."<br />"); } } function ExtractOasisType($Type) { $NewStr = str_replace('b', '', $Type); return $NewStr; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/170203-solved-im-not-sure-whats-missing/ Share on other sites More sharing options...
sasa Posted August 14, 2009 Share Posted August 14, 2009 for ($X = $StartX;$StartX<=$EndX;$X++) { for ($Y = $StartY;$StartY<=$EndY;$Y++) { $RandomChoice = $ThePool[array_rand($ThePool)]; if (is_numeric($RandomChoice)) { $MapType = $RandomChoice; $OasisType = '0'; } else { $MapType = '0'; $OasisType = ExtractOasisType($RandomChoice); } $StartID += 1; print("StartID: ".$StartID." X: ".$X." Y: ".$Y." MapType: ".$MapType." OasisType: ".$OasisType."<br />"); } } change variable name in loop Quote Link to comment https://forums.phpfreaks.com/topic/170203-solved-im-not-sure-whats-missing/#findComment-897847 Share on other sites More sharing options...
deadlyp99 Posted August 14, 2009 Author Share Posted August 14, 2009 Ah I see now. Thanks a lot. In addition I had to change a bit more in the loops for ($X = $StartX;$X<=$EndX;$X++) { for ($Y = $StartY;$Y<=$EndY;$Y++) { But it all worked out wonderfully, so thanks again Quote Link to comment https://forums.phpfreaks.com/topic/170203-solved-im-not-sure-whats-missing/#findComment-897849 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.