|
What's wrong with my code? It just keeps on generating buildings, doesn't stop.
Thanks!
(comments are locked)
|
|
break; at the end of each case! I feel so stupid...how did I miss that?
Apr 22 '11 at 08:24 PM
Muzz 1
Actually, I tried that and it still doesn't work.
Apr 22 '11 at 08:32 PM
Muzz 1
Well, it WAS a problem. Now print the value of numberOfBuildings and make sure it is decreasing over time.
Apr 22 '11 at 08:53 PM
flaviusxvii
(comments are locked)
|
|
Actually, the problem is the if statement, more specifically the semi-colon:
which is interpreted as
The rest of the code is always executed, as it's outside the if statement. I also agree that it needs braces enclosing the logic after the if statement, unless js doesn't require this? Fixed code (including break;s): I already said that.
Apr 24 '11 at 12:03 AM
burgunfaust
Yes, and I agreed. You didn't mention the surplus semi-colon, though you did fix that in your code.
Apr 24 '11 at 10:23 PM
Seregon
Well if he had only one line to execute in his if statement, then the one semicolon would have been right.
Apr 25 '11 at 12:51 AM
burgunfaust
(comments are locked)
|
|
Your problem is that you need to braces for your if statment. Nope, you dont allways have to do that.
Apr 23 '11 at 08:35 AM
OrangeLightning
But in this case it breaks the script with out it. Put them in and it works. The only time I know where you don't need it is if there is only 1 thing to execute, but this script needs more than that. That -1 is bull, because It works now.
Apr 23 '11 at 01:00 PM
burgunfaust
I've got braces...look the line below.
Apr 23 '11 at 05:07 PM
Muzz 1
Not in your original code up top you don't. You have one for the Update and the switch but not the if. function Update () { if (numberOfBuildings > 0); buildingNumber = Random.Range (1,3); randomIndent = Random.Range (randomIndentLow, randomIndentHigh);
Apr 24 '11 at 12:03 AM
burgunfaust
Actually burgunfaust has it right, his code change along with the added breaks fixes the original code, though I explained it better later, this is the correct solution. +1
Apr 24 '11 at 10:57 PM
Seregon
(comments are locked)
|
