Caution!
This is the correct version:
action super_thing()
{
var Boop; //declared before the loop
while(1)
{
...
Boop+=1*time_step;
}
}
This is wrong:
action super_thing()
{
while(1)
{
var Boop; //declared before the loop
Boop+=1*time_step;
}
}
Yes, it will compile. Yes, it may work in some special cases.
BUT: Boop is uninitialized and may contain ANY value possible.Look at this example:
#include <acknex.h>
function main()
{
int a = 10;
{
int b;
b += 20;
printf("1: %d %d", a, b);
}
{
int b;
b += 20;
printf("1: %d %d", a, b);
}
}
I got the following results:
So you can't rely that local variables will be initialized. Also, if they are initialized with zero, you will get your variable reset each iteration of the loop.