Okay Guys can you please see whats wrong here?
Posted:
Sun Jan 01, 2012 4:49 am
by raminkhan
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.
Re: Okay Guys can you please see whats wrong here?
Posted:
Sun Jan 01, 2012 6:01 am
by skydereign
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.
Re: Okay Guys can you please see whats wrong here?
Posted:
Sun Jan 01, 2012 12:09 pm
by foleyjo
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
Re: Okay Guys can you please see whats wrong here?
Posted:
Sun Jan 01, 2012 2:55 pm
by Jagmaster
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.