1

I have later done with waitForClick() function but want to know whats the problem with the below code.

bool start = true;

while (lives > 0 && bricks > 0)
{

    // Creates a mouse event
    GEvent event = getNextEvent(MOUSE_EVENT);

    while (start)
    {
        if (event != NULL)
        {
            if (getEventType(event) == MOUSE_CLICKED)
            {
                start = false;
            }
        }
    }
2
  • you don't have to write a waitForClick function. there's a function already in the SPL called waitForClick. see cdn.cs50.net/2014/fall/psets/3/pset3/spl/doc/…! – kzidane Oct 3 '15 at 20:43
  • ya i know that. I have already implemented it using the waitForClick() from the SPL Library. But still i would like to know whats wrong with this piece of code. why it freezes – Sumit Bawri Oct 3 '15 at 20:49
3

the problem is obviously that you're not updating event. that is, you're getting the next event only once. if it doesn't happen to be a mouse click, the value of event never changes and your program is stuck in an infinite loop as control never leaves the nested while loop.

1
  • Thanks. It worked – Sumit Bawri Oct 3 '15 at 21:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .