While ACS automatically sets all variables to 0, ZScript might not. I wouldn't be surprised it it had the same behaviour as C/C++ regarding uninitialized variables. (i.e. whatever garbage data was in the memory already becomes the variable's value). Of course, it could always be a bug.Vaecrius wrote:Thanks, good catch - I totally forgot to consider that what with my adventures in mousecrash wackyland. (see closed bugs forum)
Another weird problem: I've got this code:and so on, with each "HDWeapon" owned by the caller adding a different value to "blx".Code: Select all
... thinkeriterator it=thinkeriterator.create("HDWeapon"); HDweapon hdw; while( hdw=HDWeapon(it.Next()) ){ if(hdw.owner==self){ int blx; if(hdw is "Lumberjack"){ blx+=100; if(hdw.weaponstatus[1]>=0)blx+=BLOX_BATTERY_LOADED; }else if(hdw is "HDPistol"){ ...
Which works fine, except this ends up with "blx" being some obscenely high number unless I explicitly reset it with "int blx=0". Why is this? Shouldn't that int be re-initialized every time that block is run?
(IMO all languages should initialize variables on definition. As a good example, D does this in a way that helps in finding bugs. Integers are initialized to zero, floating point types are initialized to NaN, etc.)