Results 1 to 2 of 2

Thread: Getting object by string name

  1. #1

    Getting object by string name

    I created a vehicle in the mission editor. Knowing the name of that vehicle, how can I get an object handle to it in a script? I've tried:

    call compile "_vehObj = "+objectName";

    but no go. In theory, I guess you could loop through every vehicle in the mission until you find the one that has the right name, but that is extraordinarily inefficient. Any thoughts?


  2. #2
    well (if I understand the question??) generally you would do this:
    _hdl = [objectName] execVM "someScript";
    [objectName] call someFunction;
    [objectName] spawn {someThing};
    then in the script:
    _object = _this select 0;
    another way is to save the object as a variable:

    _veh = createVehicle ["B_G_Quadbike_01_F", position player, [], 0, "NONE"];
    missionNamespace setVariable ["refString",_veh];//"refString" can be anything you like but try to make it unique so it doesn't get overwritten
    In a script
    _veh = missionNamespace getVariable "refString";
    _veh setDamage 1;
    will return the object reference

    If you create multiple vehicles:
    _vehArr = []
    _vehrefArr = []
    for "_i" from 0 to 9 do {
    _veh = createVehicle ["B_G_Quadbike_01_F", position player, [], 0, "NONE"];
    _ref = format ["quad%1",_i];
    missionNamespace setVariable ["_ref",_veh];
    _vehArr set [count _vehArr,_veh];
    _vehrefArr set [count _vehrefArr,_ref];
    missionNamespace setVariable ["quadVehicles",_vehArr];
    missionNamespace setVariable ["quadVehRefs",_vehrefArr];
    You now have 3 ways of accessing the stored data in another script:
    _vehref = missionNamespace getVariable "quad9"; //the individual vehicles - strings "quad0" - "quad9"
    _vehArr = missionNamespace getVariable "quadVehicles";//array of vehicles _vehArr select 0 to _vehArr select 9;
    _vehrefArr = missionNamespace getVariable "quadVehRefs";//array of reference strings ["quad0" ..."quad9"]
    _my1stVeh = missionNamespace getVariable (_vehrefArr select 0);
    Last edited by Mattar_Tharkari; Dec 1 2013 at 22:59.
    "I believe everything. And l believe nothing. I suspect everyone. And l suspect no one. I gather the facts, examine the clues... and before you know it, the case is sol-ved!"
    Arma III

Similar Threads

  1. Converting string from array into object name
    By cds1984 in forum ARMA 3 - MISSION EDITING & SCRIPTING
    Replies: 2
    Last Post: Sep 29 2013, 10:10
  2. [Sccript Help] Error damage: Type String, expected Object
    By GreigPil in forum ARMA 3 - MISSION EDITING & SCRIPTING
    Replies: 16
    Last Post: Jul 21 2013, 21:16
  3. Only player can activate a trigger? - Call Object with its Name as string?
    By AAD10 Pete in forum ARMA 2 & OA : MISSIONS - Editing & Scripting
    Replies: 4
    Last Post: Oct 6 2009, 21:07
  4. object returned as string!?
    By Combat-Agent in forum OFP : MISSION EDITING & SCRIPTING
    Replies: 5
    Last Post: Aug 10 2006, 23:01
  5. Converting string value to object name!
    By The_Captain in forum OFP : MISSION EDITING & SCRIPTING
    Replies: 12
    Last Post: Oct 16 2002, 05:11

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts