Jump to content
Sign in to follow this  
Scrocco88

Access by object name

Recommended Posts

How can i get (in a script) the Object reference to an object created in the editor, having his name stored in a variable?

Something like:

_variable = "my_object_name";
_obj = getObjectByName _variable;

Share this post


Link to post
Share on other sites

mmm... i think it's not what i asked for.

vehicleVarName:

Returns the name of the variable which contains a primary editor reference to this object. This is the variable given in the Insert Unit dialog / name field, in the editor. It can be changed using setVehicleVarName.

setVehicleVarName

Sets the name of the variable which contains a reference to this object.

In both cases you already have an Object variable, and you manipulate it's name. I need to GET the object already HAVING his name, stored in a String variable.

vehicleVarName Syntax:

String = vehicleVarName objectName
[b]Parameters: [/b]objectName: Object
[b]Return Value:[/b] String

I'm looking for something like

object = <something> objectName
[b]Parameters:[/b] objectName: String
[b]Return Value: [/b]object

Share this post


Link to post
Share on other sites

Does someone have the solution ?

I am still blocked on this issue:

_myObjectName = "first_laptop";
_myObjectInstance = ?????? ;     // Looking for something like   BIS_fn_GetObjectByName _myObjectName
_res = alive _myObjectInstance;           // if I use _myObjectName instead, there is an error: Error alive: Type String, expected Object

Share this post


Link to post
Share on other sites
_myObjectName = "first_laptop";
_myObjectInstance = missionNamespace getVariable [_myObjectName , objNull];
if (isNull _myObjectInstance ) exitWith{
   ["Null ref %1", _myObjectName] call BIS_fnc_error;
};

_res = alive _myObjectInstance;           // if I use _myObjectName instead, there is an error: Error alive: Type String, expected Object

Share this post


Link to post
Share on other sites

_myObjectInstance = objNull;

{if ((vehicleVarName _x) == "first_laptop") exitWith {_myObjectInstance = _x}} forEach (allMissionObjects "Laptop");

if (!(isNull _myObjectInstance)) then {...};

Also should work

_myObjectInstance = missionNamespace getVariable ["first_laptop", objNull];

if (!(isNull _myObjectInstance)) then {...};

Edited by Schatten

Share this post


Link to post
Share on other sites
_myObjectInstance = missionNamespace getVariable [_myObjectName , objNull];

Does the job ! Big thank you :yay:

@Schatten: thks too, but I was looking for optimized code, with no loop...

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×