Jump to content

[SOLVED] Local variables


photo

Recommended Posts

Hello. I cant understand how local variables works.
i'm using Unigine v1

code:

class Building
void setState()

{

  int k;
   ...
  k++;
  engine.console.print(typeinfo(k) + " \n");
   ...
}

On Initialisation scene several objects of Building are creared and in In Update setState() are call every second.

output:
1
2
3
4
5
...

The question is why  int k; do not create new local variable and takes old value?
Link to comment

Hi there!

 

That's because you used uninitialised local variable here which is a bad practice in general.

 

One thing you should know about though is that local variables in Unigine aren't local. They're more like local variable with static modifier in C++. In other words, they're global but visible only in that function.

 

It's not a big deal as long as you assign some values to them.

Link to comment
×
×
  • Create New...