- Home /
 
Variable i
Hi,
I am using this script for particle simulation
 for (i = 0; i < 10; i++) {
 
     particleEmitter.Simulate(1.0);
 
 }
 
               Now, in unity, I get
BCE0005: Unknown identifier: 'i'.
I know this should be obvious, but do I have to define i?
Answer by Eric5h5 · Apr 03, 2012 at 02:17 AM
 for (var i = 0; i < 10; i++) {
 
              just be aware if you use this twice in the same GameLoop/frame, another error shall occur. (declaring a var that is already declared).
Personally I declare all my for_loop vars at the start :
 private var i : int = 0;
 
 
                  if you add this at the start then your script shall work.
You should declare your loop variable locally and not in the class. Not only does it reduces cluttering but I think its slightly faster. $$anonymous$$y two cents :)
Right, don't declare variables outside functions unless necessary. If you really need to, you can use #pragma implicit in order to do "for (i = 0..." without having to declare variables explicitly using var, but that's generally not recommended (it's there for compatibility with old code). At least do
 var i : int;
 for (i = 0...
 
                  inside functions, rather than making "i" a class variable, which is poor practice.
Your answer