sargken 286 Posted July 10, 2014 Hi i need some help fixing this script i keep getting an error at this point. Error is undefined variable : _min_factory ["vehiclequeue", []] call stats_init_variable; ["aircraftqueue", []] call stats_init_variable; ["tvehiclequeue", []] call stats_init_variable; ["weaponqueue", []] call stats_init_variable; ["itemqueue", []] call stats_init_variable; ["avehiclequeue", []] call stats_init_variable; ["tavehiclequeue", []] call stats_init_variable; ["alcoholfactoryqueue", []] call stats_init_variable; ["terrorfactoryitemsqueue", []] call stats_init_variable; ["diamondqueue", []] call stats_init_variable; ["furnacequeue", []] call stats_init_variable; factory_object = 0; factory_id = 1; factory_name = 2; factory_crate = 3; factory_spawn = 4; factory_items = 5; factory_cost = 6; factory_storage = 7; factory_queue = 8; all_factories = [ [ Vehiclefactory, "factory1", "Vehicle Factory", dummyobj, vfacspawn, _vehiclefactory, 5000000, "Fabrikablage1", "vehiclequeue"], [ Aircraftfactory, "factory2", "Aircraft Factory", dummyobj, airfacspawn, _aircraft_factory, 8000000, "AircraftFactory1", "aircraftqueue"], [ ItemFabrik_1, "factory3", "General Factory", igunbox,dummyobj, _itemfactory, 650000, "Fabrikablage3", "itemqueue"], [ weaponfactory, "factory4", "Weapon Factory", wfgunbox,dummyobj, _weaponfactory, 10000000, "Fabrikablage4", "weaponqueue"], //[terrorshop2,"factory5","Terror Factory",dummyobj,tfacspawn,_terrorfactory,300000,"Fabrikablage5", "tvehiclequeue"], [ tairshop, "factory6", "Terrorist Vehicle Factory", dummyobj,tairspawn, _tairfactory, 20000000, "Fabrikablage6", "tavehiclequeue"], [ alcoholfactory, "factory7", "Alcohol Factory", dummyobj, dummyobj, _alcoholfactory, 1000000, "Fabrikablage7", "alcoholfactoryqueue"] , //[terrorfactoryitems, "factory8", "Terror item factory", tgunbox,dummyobj, _terrorfactoryitems, 600000, "Fabrikablage8", "terrorfactoryitemsqueue"] [ ringfactory, "factory9", "Ring Factory", dummyobj, dummyobj, _ringfactory, 2500000, "Fabrikablage9", "diamondqueue"], [ Furnace, "factory10","Furnace", dummyobj, dummyobj, _furnace, 1500000, "Fabrikablage10","furnacequeue"] ]; }; factory_init = { //player groupChat format["factory_init %1", _this]; private["_player", "_factory_id"]; _player = _this select 0; _factory_id = _this select 1; if (not([_player] call player_human)) exitWith {}; if (isNil "_factory_id") exitWith {}; if (typeName _factory_id != "STRING") exitWith {}; private["_factory", "_queue_name", "_items"]; _factory = [_factory_id] call factory_lookup_id; if (isNil "_factory") exitWith {}; _queue_name = _factory select factory_queue; _items = _factory select factory_items; private["_workers_name", "_workers"]; _workers_name = format["%1workers", _queue_name]; [_workers_name, 0] call stats_init_variable; { private["_item", "_prod_name", "_eta_name", "_pend_name", "_avail_name"]; _item = _x; _avail_name = format["%1avail", _item]; _pend_name = format["%1pend", _item]; _eta_name = format["%1eta", _item]; _prod_name = format["%1prod", _item]; [_avail_name, 0] call stats_init_variable; missionNamespace setVariable [_pend_name, 0]; missionNamespace setVariable [_eta_name, 0]; missionNamespace setVariable [_prod_name, 0]; } forEach _items; private["_queue"]; _queue = missionNamespace getVariable _queue_name; { private["_item", "_pend_name"]; _item = _x; _pend_name = format["%1pend", _item]; _pend = missionNamespace getVariable _pend_name; _pend = _pend + 1; missionNamespace setVariable [_pend_name, _pend]; } forEach _queue; }; factory_calculate_production_cost = { //player groupChat format["factory_calculate_production_cost %1", _this]; private["_item"]; _item = _this select 0; if (isNil "_item") exitWith {0}; if (typeName _item != "STRING") exitWith {0}; private["_buy_price"]; _buy_price = (_item call INV_GetItemBuyCost); _sell_price = (_item call INV_GetItemSellCost); // simple forumla for calculating the production cost // in order for factory owner, to make a profit, the production cost // must be lower than the amount the items sells for ... // whatever extra money the factory owner makes after selling the item is // called the profit margin. // We are fixing here the profit margin to 10% private["_profit_margin"]; _profit_margin = 0.3; private["_cost"]; _cost = _sell_price - _sell_price * _profit_margin; (_cost) }; factory_calculate_production_time = { //player groupChat format["factory_calculate_production_time %1", _this]; private["_item", "_workers"]; _item = _this select 0; _workers = _this select 1; if (isNil "_item") exitWith {0}; if (isNil "_workers") exitWith {0}; if (typeName _item != "STRING") exitWith {0}; if (typeName _workers != "SCALAR") exitWith {0}; if (_workers <= 0) exitWith {0}; private["_item_cost"]; _item_cost = (_item call INV_GetItemBuyCost); // simple linear formula for calculating the production time ... // the more workers you have, the lower the production time // the more expensive the item is the higher the production time private["_eta"]; _eta = (_item_cost * 0.01125); _eta = (_eta) min( maxmanitime); _eta = (_eta * 5) / _workers; _eta = round(_eta); _eta }; factory_lookup_id = { private["_id"]; _id = _this select 0; if (isNil "_id") exitWith {nil}; if (typeName _id != "STRING") exitWith {nil}; private["_factory"]; _factory = nil; { private["_cfactory", "_cid"]; _cfactory = _x; _cid = _cfactory select factory_id; if (_id == _cid) exitWith { _factory = _cfactory; }; } forEach all_factories; _factory }; factory_player_near = { //player groupChat format["factory_player_near %1", _this]; private["_player", "_distance"]; _player = _this select 0; _distance = _this select 1; if (not([_player] call player_exists)) exitWith {nil}; if (isNil "_distance") exitWith {nil}; if (typeName _distance != "SCALAR") exitWith {nil}; private["_min_distance", "_min_factory"]; _min_distance = _distance; _min_factory = nil; { private["_cfactory", "_cdistance", "_cobject"]; _cfactory = _x; _cobject = _cfactory select factory_object; _cdistance = _player distance _cobject; if (_cdistance < _min_distance) then { _min_distance = _cdistance; _min_factory = _cfactory; }; } forEach all_factories; _min_factory }; Share this post Link to post Share on other sites
node 10 Posted August 19, 2014 Change _min_factory = nil; to either _min_factory = _nil; or _min_factory = _nul; Share this post Link to post Share on other sites
opusfmspol 282 Posted August 19, 2014 (edited) In 1.63 nil variables are deleted (they used to be kept). Using _nul as suggested won't work unless _nul is also defined (else you'll get another undefined variable error). You should predefine _min_factory by its null type, objNull. Using null type, if it's being returned, any check on the return should use if IsNull/if !isNull rather than if isNil/if !isNil. From the 1.63 changelog: [97926] Changed: Scripting: When a global variable is assigned a nil value, it is now deleted (was kept with a nil value). Edited August 19, 2014 by OpusFmSPol added changelog mention Share this post Link to post Share on other sites