fusion13 11 Posted December 19, 2013 Hello, I am trying to make a array of objects this is what I have objectarray = ["sign","this1"]; if(!(obj in objectarray))exitwith{obj addAction ["Move this object!", {execVM "move.sqf";}];_handled=true;}; I want it to make SEVERAL object display this addAction Thanks, Fusion :dancehead: Share this post Link to post Share on other sites
bangabob 45 Posted December 20, 2013 objectarray = ["sign","this1"]; { _x addAction ["Move this object!", {execVM "move.sqf";}]; }foreach objectarray; Share this post Link to post Share on other sites
fusion13 11 Posted December 20, 2013 objectarray = ["sign","this1"]; { _x addAction ["Move this object!", {execVM "move.sqf";}]; }foreach objectarray; Didn't work for somereaso :/ Share this post Link to post Share on other sites
naught 6 Posted December 20, 2013 Also, be aware that objects cannot be represented by strings unless doing some global variable look-up via namespaces and the getVariable command. Give this a read to get a better understanding of data types in Arma, since I've seen you mix them up a few times: http://community.bistudio.com/wiki/Data_Types And read this too if you want to better understand the usage of variables (since I think you want to use a local variable in the above example instead of a global one): http://community.bistudio.com/wiki/Variables ---------- Post added at 19:52 ---------- Previous post was at 19:50 ---------- So you want this: private ["_objectarray"]; _objectarray = [sign, this1]; { // forEach _x addAction ["Move this object!", {[] execVM "move.sqf";}]; } foreach _objectarray; Or, if the array is static, you can make it even more efficient: { // forEach _x addAction ["Move this object!", {[] execVM "move.sqf";}]; } foreach [sign, this1]; Share this post Link to post Share on other sites
fusion13 11 Posted December 20, 2013 Also, be aware that objects cannot be represented by strings unless doing some global variable look-up via namespaces and the getVariable command.Give this a read to get a better understanding of data types in Arma, since I've seen you mix them up a few times: http://community.bistudio.com/wiki/Data_Types And read this too if you want to better understand the usage of variables (since I think you want to use a local variable in the above example instead of a global one): http://community.bistudio.com/wiki/Variables ---------- Post added at 19:52 ---------- Previous post was at 19:50 ---------- So you want this: private ["_objectarray"]; _objectarray = [sign, this1]; { // forEach _x addAction ["Move this object!", {[] execVM "move.sqf";}]; } foreach _objectarray; Or, if the array is static, you can make it even more efficient: { // forEach _x addAction ["Move this object!", {[] execVM "move.sqf";}]; } foreach [sign, this1]; <333333, Now one last question for you, How could I make the move.sqf change for the object it chose sing attachTo [player,[0,2,1]]; //this change per item detach = player addAction ["Let Go", {execVM "tools\detach.sqf";}]; Share this post Link to post Share on other sites
naught 6 Posted December 20, 2013 The addAction command has several useful parameters which it passes to the script which it calls, as seen here: http://community.bistudio.com/wiki/addAction If I'm understanding correctly that your attachTo position changes per object (if it didn't this may look simpler), then your script could look something like this: { // forEach (_x select 0) addAction ["Move Object", { private ["_target", "_caller", "_actID", "_args"]; _target = _this select 0; _caller = _this select 1; _actID = _this select 2; _args = _this select 3; // In this case we passed the attachTo position as our _args _target removeAction _actID; _target attachTo [_caller, _args]; _caller addAction ["Let Go", "tools\detach.sqf", [_target]]; // Adds the new action, passes _target as ((_this select 3) select 0) }, (_x select 1)]; } foreach [ [sign, [0,2,1]], [this1, [0,2,1]] // May need to change this positional value ]; I've been programming for a while now so if the above intimidates or confuses you I apologize, I have my own coding style that I cannot seem to break :P Share this post Link to post Share on other sites
fusion13 11 Posted December 20, 2013 The addAction command has several useful parameters which it passes to the script which it calls, as seen here: http://community.bistudio.com/wiki/addActionIf I'm understanding correctly that your attachTo position changes per object (if it didn't this may look simpler), then your script could look something like this: { // forEach (_x select 0) addAction ["Move Object", { private ["_target", "_caller", "_actID", "_args"]; _target = _this select 0; _caller = _this select 1; _actID = _this select 2; _args = _this select 3; // In this case we passed the attachTo position as our _args _target removeAction _actID; _target attachTo [_caller, _args]; _caller addAction ["Let Go", "tools\detach.sqf", [_target]]; // Adds the new action, passes _target as ((_this select 3) select 0) }, (_x select 1)]; } foreach [ [sign, [0,2,1]], [this1, [0,2,1]] // May need to change this positional value ]; I've been programming for a while now so if the above intimidates or confuses you I apologize, I have my own coding style that I cannot seem to break :P The postion dosen't change jsut object name Share this post Link to post Share on other sites
naught 6 Posted December 20, 2013 In that case then this simpler function will also work: { // forEach _x addAction ["Move Object", { private ["_target", "_caller", "_actID"]; _target = _this select 0; _caller = _this select 1; _actID = _this select 2; _target removeAction _actID; _target attachTo [_caller, [0,2,1]]; _caller addAction ["Let Go", "tools\detach.sqf", [_target]]; // Adds the new action, passes _target as ((_this select 3) select 0) }]; } foreach [sign, this1]; Share this post Link to post Share on other sites
fusion13 11 Posted December 20, 2013 { // forEach _x addAction ["Place Object", { private ["_target"]; _target = _this select 0; detach _target; }]; } foreach [sign, this1]; For the detach not working? I may have screwed it up? Share this post Link to post Share on other sites
naught 6 Posted December 20, 2013 // File: "scripts\move.sqf" { // forEach _x addAction ["Move Object", { private ["_target", "_caller", "_actID"]; _target = _this select 0; _caller = _this select 1; _actID = _this select 2; _target removeAction _actID; _target attachTo [_caller, [0,2,1]]; _caller addAction ["Let Go", { private ["_target", "_caller", "_actID", "_object"]; _target = _this select 0; _caller = _this select 1; _actID = _this select 2; _object = _this select 3; _target removeAction _actID; detach _object; [] call compile preprocessFileLineNumbers "scripts\move.sqf"; }, _target]; }]; } foreach [sign, this1]; Share this post Link to post Share on other sites
fusion13 11 Posted December 20, 2013 (edited) Thanks man, I kinda suck with this kinda of stuff :P :dancehead: After certain amounts of moving it stops working? Update it displays two "Move Object"'s and it will only work twice.. :/ Edited December 20, 2013 by Fusion13 Error Share this post Link to post Share on other sites