x


Stuck while solving a Coroutine problem

Hey guys, I’ve been stuck on this problem for almost two days, and I can’t seem to be able to figure it out on my own, so I would really appreciate your help. First of all, here’s my code.

    function Update () 
{

    if ((takeTurns.machineTurn == true)&&(takeTurns.playerTurn == false))
       JustACoroutine();
}


    function JustACoroutine()
    {
       yield WaitForSeconds(5);

       for (var f = 0; f <50; f++)
       {
         for (var w = 0; w < 50; w++)
         {
          if (createBricks.globalArray[w,f,0] != null)
          {
              if(createBricks.globalArray[w,f,0].gameObject.GetComponent(Rigidbody) != null)
              {
                 Destroy(createBricks.globalArray[w,f,0].gameObject);
              }
          }
         }
       }
       allMurdered = true;
    }

The problem is, allMurdered remains true indefinitely. That is, long after takeTurns.playerTurn had been switched to true and takeTurns.machineTurn to false. Here’s the bit of code that does that:

function LookForClicks()
{
    if (createBricks.turnClicks == 4)
    {
        playerTurn = false;
        machineTurn = true;
        createBricks.turnClicks = 0;
        yield WaitForSeconds(6);
        murderer.allMurdered = false;
        playerTurn = true;
        machineTurn = false;

    }
}

I believe that the problem lies in having two coroutines running simultaneously, but then I don’t understand them very well and can’t quite put my hand on the flawed part.

Again, any help at all very appreciated.

more ▼

asked Feb 25 '12 at 03:12 AM

krides gravatar image

krides
23 6 9 11

(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3455
x333
x323
x239
x63

asked: Feb 25 '12 at 03:12 AM

Seen: 380 times

Last Updated: Feb 25 '12 at 03:12 AM