Caution!

This is the correct version:
Code:
action super_thing()
{
  var Boop; //declared before the loop
  while(1)
  {
    ...
    Boop+=1*time_step;
  }
}




This is wrong:
Code:
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:
Code:
#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:
Originally Posted By: Run 1

1: 10 3406956
2: 10 3810


Originally Posted By: Run 2

1: 10 20
2: 10 99345


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.


Visit my site: www.masterq32.de