Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have the following arrays:

[costs] => Array (
   [0] => Array (
       [value] => 600
       [name] => Wood
   )
   [1] => Array (
       [value] => 200
       [name] => Stone
   )
   [2] => Array (
       [value] => 800
       [name] => Iron
   )
   [3] => Array (
       [value] => 300
       [name] => Gold
   )
)

Array (
    [0] => Array (
        [balance] => 70636.86
    )
    [1] => Array (
        [balance] => 70636.86
    )
    [2] => Array (
        [balance] => 70636.38
    )
    [3] => Array (
        [balance] => 141072.77
    )
)

I want to check if the second array enough resources to spend from the first array and if one of the values from the first array is not = or less. Can someone help me out?

What I've tried so far:

for($i = 0; $i < 4; $i++)
{
    $balance = $this->listResources[$i]['balance'];
    if($balance >= $this->buildingCosts[$i]['value'])
        $this->listBuildings[$i][$this->listKey]['status'][$balance] = '1';
    else
        $this->listBuildings[$i][$this->listKey]['status'] = '0';
}

What I'm trying to find out is to see if I have enough resources in array to spend ( values that I need are found in costs )

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

Your question is extremely cryptic (we can only vaguely guess, for example, that $this->listKey in some way refers to the building type you're trying to create, and some of your sentences are unintelligible), but I suspect you mean something like:

for($i = 0; $i < 4; $i++) {
    $balance = $this->listResources[$i]['balance'];
    $this->listBuildings[$this->listKey]['status'][$i] = ($balance >= $this->buildingCosts[$i]['value']);
}

That populates $this->listBuildings with status arrays that map resource index numbers to booleans indicating whether or not the available quantity of that resource is sufficient.

share|improve this answer
    
thanks it works, i was in a hurry when i posted this and very angry because it didn't work the way i wanted :-) –  Bogdan May 23 '12 at 18:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.