SSgt 'Ice Cold' Sykes 1 Posted December 13, 2018 Hi, I'm trying to set up a minefield module via script. I get an error when using local variables while everything works fine with global variables. If anyone could tell why that'd be great. Here's my code : POP_fnc_Minefield = { if ((typename _this != "ARRAY") or (count _this < 3)) exitWith {hint format ["Error : POP_fnc_Minefield argument : %1", _this];}; _MineGroup = createGroup [(_this select 0), true]; _pos = _this select 1; _FieldSize = _this select 2; if (count _this <= 3) then {_NbMines = floor(_FieldSize/2);} else {_NbMines = floor(_FieldSize/2*(_this select 3));}; if (count _this <= 4) then {_MineType = "APERSMine";} else {_MineType = this select 4;}; if (count _this <= 5) then {_FieldCond = TRUE;} else {_FieldCond = _this select 5;}; _Minefield = "Site_Minefield" createUnit [ _pos, _MineGroup, format [ "this setVariable ['minescount', '%1']; this setVariable ['minestype', '%2']; this setVariable ['axisa', '%3']; this setVariable ['axisb', '%3']; this setVariable ['shape', 'Rectangle']; this setVariable ['side', 'Independent']; this setVariable ['marked', 'Friendlies']; this setVariable ['conditionofpresence', '%4'];", _NbMines, _MineType, _FieldSize, _FieldCond ] ]; }; This code throws undefined variable errors but if replace _NbMines, _MineType, _FieldCond with NbMines, MineType, FieldCond then everything seems to work fine. Share this post Link to post Share on other sites
gc8 977 Posted December 13, 2018 One thing I noticed is that the version of createUnit you are using does not return object. Wiki states this 1 Share this post Link to post Share on other sites
davidoss 552 Posted December 13, 2018 POP_fnc_Minefield = { params [ ["_side","Independent",[""]], ["_pos",[],[[]]], ["_FieldSize",0,[0]], //optional below ["_NbMines",floor ((_this select 2)/2),[0]], ["_MineType","APERSMine",[""]], ["_FieldCond",true,[true]] ]; if ( !(_pos isEqualType []) || (count _pos) < 2 || isnil {_this select 2}) exitWith {hint format ["Error : POP_fnc_Minefield argument : %1", _this]}; private _MineGroup = createGroup [call compile _side, true]; private _Minefield = _MineGroup createUnit ["Site_Minefield", _pos, [], 0, "CAN_COLLIDE"]; {_Minefield setVariable _x} forEach [ ["minesCount",format ["%1",_NbMines]], ["minesType", _MineType], ["axisA", format ["%1",_FieldSize]], ["axisB", format ["%1",_FieldSize]], ["shape", "Rectangle"], ["marked", "Friendlies"], ["side",_side], ["conditionofpresence", format ["%1",_FieldCond]] ]; (_Minefield) }; _minefield = ["Independent",position player,100] call POP_fnc_Minefield 2 1 Share this post Link to post Share on other sites
SSgt 'Ice Cold' Sykes 1 Posted June 18, 2019 On 12/13/2018 at 11:00 PM, davidoss said: POP_fnc_Minefield = { params [ ["_side","Independent",[""]], ["_pos",[],[[]]], ["_FieldSize",0,[0]], //optional below ["_NbMines",floor ((_this select 2)/2),[0]], ["_MineType","APERSMine",[""]], ["_FieldCond",true,[true]] ]; if ( !(_pos isEqualType []) || (count _pos) < 2 || isnil {_this select 2}) exitWith {hint format ["Error : POP_fnc_Minefield argument : %1", _this]}; private _MineGroup = createGroup [call compile _side, true]; private _Minefield = _MineGroup createUnit ["Site_Minefield", _pos, [], 0, "CAN_COLLIDE"]; {_Minefield setVariable _x} forEach [ ["minesCount",format ["%1",_NbMines]], ["minesType", _MineType], ["axisA", format ["%1",_FieldSize]], ["axisB", format ["%1",_FieldSize]], ["shape", "Rectangle"], ["marked", "Friendlies"], ["side",_side], ["conditionofpresence", format ["%1",_FieldCond]] ]; (_Minefield) }; _minefield = ["Independent",position player,100] call POP_fnc_Minefield So this has been working just fine for me until now because it seems it isn't possible to create more than one minefield. The unit gets created but there are no mines and i can't find the source of the problem. Share this post Link to post Share on other sites