Okay Guys can you please see whats wrong here?

Non-platform specific questions.

Okay Guys can you please see whats wrong here?

Postby raminkhan » Sun Jan 01, 2012 4:49 am

I am trying to design a random timer which a ball gets destroyed and re-created base on a random time frame so I attached a picture for you to see for my code. please let me know whats wrong here.
Attachments
Problem.jpg
raminkhan
 
Posts: 63
Joined: Mon Sep 12, 2011 3:35 pm
Score: 0 Give a positive score

Re: Okay Guys can you please see whats wrong here?

Postby skydereign » Sun Jan 01, 2012 6:01 am

That error is caused by your use of fire in the 5th line. For that error to happen, fire cannot be a variable. If you make it one, then it should work. Also, do you know how to use a switch statement? The image quality is poor, so I can't see exactly what you were doing, but your bracket placement within the case 0 seems weird. Also, you'll never get decision to equal 0 with that code. You need to drop the +1 for that to work.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Okay Guys can you please see whats wrong here?

Postby foleyjo » Sun Jan 01, 2012 12:09 pm

You also have a redundant case in your switch statement.

You are adding 1 to the randomly generated decision.
Therefore there will never be a case 0
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: Okay Guys can you please see whats wrong here?

Postby Jagmaster » Sun Jan 01, 2012 2:55 pm

Do you have brackets in between your switch cases like this?

Code: Select all
switch(decision)
{
       case 0: {fire=1}
       {
        yvelocity =5;
       }
       break;
}


If so, you don't need those brackets. Do it like this.

Code: Select all
switch(decision)
{  // <--- only one pair of brackets needed. That's the beauty of switch!

     case 0:

     fire=1;
     yvelocity=5;

     break;
     

     // now you're ready for the next case!
    case 1:// <<< notice a colon goes here

    // put whatever you need to happen when decision == 1 here.

    break; // <<< and a semicolon goes here

} // << last bracket.

User avatar
Jagmaster
 
Posts: 875
Joined: Sun May 08, 2011 4:14 pm
Location: Not where you think.
Score: 82 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest