a.koryakin Posted November 24, 2014 Posted November 24, 2014 Hello. I cant understand how local variables works.i'm using Unigine v1code: class Buildingvoid 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: 12345...The question is why int k; do not create new local variable and takes old value?
unclebob Posted November 24, 2014 Posted November 24, 2014 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.
a.koryakin Posted November 25, 2014 Author Posted November 25, 2014 Thx unclebob.So solution is: i always have to initialize local variables before using it.
Recommended Posts