Loop Logic

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
User avatar
Xaos
Posts: 940
Joined: Wed Jan 11, 2012 4:01 am

Loop Logic

Post by Xaos »

So I have an array that I'm looping through. I need to check to see if the array values match another value, and if so, check for one of three conditions. 2/3 of the conditions will have the runner go into the hole (The desired result), but the third will cause the check for that value to end, and the array loop should continue. This check has to come first, however. And after this check, and if the result is the 'closed' which will terminate that check, the array should be looped through normally. First look for one value from all of them, if that isn't true, look for another, and if that's not true, default back to the first value checked.

Code: Select all

function running(){
$c = 0;
$visionCheck = rand(1,100); //Do a vision check, look for open gap if passed, go to play gap if its open, otherwise go to another gap. If failed, go to a random gap. 
if(($oPlayer[23]+ $oPlayer[7])/2 >= $visionCheck){ //If the player passes the vision check
for($i=0; $i > $gap.length; $i++){ //Loops through the gaps
if($gap[$i] == $play[1]){ //Checks if the gap being looped through matches the designed play gap
if($gap[$i] == 'open'){ //If the gap that matches the play gap is open
//Go there
}elseif($gap[$i] == 'partial'){ //If the play gap is partially open
//Go there
}elseif($gap[$i] == 'closed'){ //If the play gap is closed
$c = 1; //End check for play-gap.
}
}
}elseif($gap[$i] != $play[1]){ //If the gap doesn't match the play-gap. The check for the play gap should ALWAYS come first
if($c == 1){ //I made $c = 1 to terminat the play-gap loop through. If $C is not 1, that means the runner has an open/partially open gap on the play gap and should go there
if($gap[$i] == 'open'){ //If the first gap is open, go there
//Go there
}elseif($gap[$i] == 'partial'){
//Look for others, then go there if nothing else. Best option is to have an open gap, but 2nd best is partial. This is part where I need help, how to check all of the opens first and then check for partials.
}elseif($gap[$i] == 'closed'){
//If every gap is closed, go to the play-gap. How do I make this happen?
}
}elseif($c == 0){ //If the play-gap has not been checked, add to $i to get to the playgap.
$i++;
}
}elseif(($oPlayer[23]+ $oPlayer[7])/2 < $visionCheck){ //If the player doesn't pass the vision check
$failedCheck = rand(1,$gap.length);
//go to failedCheck gap. Random gap.
}
 
} 
I've commented on where I have some problems. I think recursion may be necessary, but not sure.
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: Loop Logic

Post by hallsofvallhalla »

hmm a bit hard to understand exactly what you want to do so I will guess. What if you create a counter that counts everytime the gap is closed and if that counter = count($gap) then go to play gap.
User avatar
Xaos
Posts: 940
Joined: Wed Jan 11, 2012 4:01 am

Re: Loop Logic

Post by Xaos »

hallsofvallhalla wrote:hmm a bit hard to understand exactly what you want to do so I will guess. What if you create a counter that counts everytime the gap is closed and if that counter = count($gap) then go to play gap.
Basically, I want the gap[] array to be ran through, and find the gap that matches the play gap (IE if playGap was 7, find gap[7]). Then check if the play gap is open or partially open. If they are, the runner goes into those gaps. If the play gap is closed, go check every other gap. First check the other gaps if they are open, and go to the first open gap. If none of them are open, then check all of them for being partially open. If all of them are neither partially open nor open, go back to the play gap. And I think the counter would work, that's kind of what I was thinking, but what about the case of Partially Open/Open? Maybe I should split the loop up. First check for the play gap, check the play gap, if its closed, have a loop that goes through and ONLY looks for open gaps, then go through and look for partial, then go back to the play gap. Do you think that makes more sense and is more efficient?
Post Reply

Return to “Advanced Help and Support”