Search the Community
Showing results for tags 'define'.
Found 1 result
-
Hello. I have a piece of code here that needs some polishing. some help to understand: _guard is in the middle of a city, _taskitems is not important right now. The for loop should go through all the houses in the area. This piece of code works 80% of the time without any problems. 20% of the time it gives me an error: "Undefined variable in the expression: _pos".Why does it work more often than not? I don't see my own mistake here. _houses = nearestObjects [_guard, ["house"], 400]; _crateSpawned = 0; _crateHouse = 0; _taskItems = []; _pos = 0; _defendergroup = createGroup civilian; for "_i" from 0 to count _houses -1 do { _item = _houses select _i; _chance = floor (random 5); if( (_chance == 1 && _crateSpawned == 0) || _houses select (count _houses -1) == _item) then { _positions = [_item] call BIS_fnc_buildingPositions; if(count _positions >3 || _houses select (count _houses -1) == _item) then { _pos = selectrandom _positions; _crate = createVehicle ["B_CargoNet_01_ammo_F",_pos, [], 0, "NONE"]; _crateSpawned = 1; _taskItems pushBack _crate; _crateHouse = _item; sleep 0.5; }; }; };