Jump to content
ACI XCIX-0001

Command Get the automatically generated variable name of an object by the engine when none as been attributed in eden editor

Recommended Posts

Afternoon !

Is there a Command to Get the automatically generated variable name of an object by the engine when none as been attributed  in eden editor. For instance get the object  var name under the current crosshair.

Share this post


Link to post
Share on other sites

in watch field of debug console:  cursorObject

Share this post


Link to post
Share on other sites

Thank for your answer !
 

It only returns the Squad for Instance : "B Alpha 1-3" and the position for instance ":1"

B Alpha 1-3:1.

The var name isn t returned.

Share this post


Link to post
Share on other sites

You can use BIS_fnc_objectVar:

_var = cursorObject call BIS_fnc_objectVar;

which will return some iteration of "bis_o###" for certain object types, but I'm not clear on the rules regarding which. You can also set a custom prefix to use instead of "bis_o."

  • Like 2

Share this post


Link to post
Share on other sites

Exactly. Harzach example is correct. Tested on a unit which have no variable from Eden and use obtained var to stop his animation for instance. Worked. But also, cursorObject gave me the same name, "bis_oXXX".

Share this post


Link to post
Share on other sites
11 hours ago, ACI XCIX-0001 said:

Is there a Command to Get the automatically generated variable name of an object by the engine when none as been attributed  in eden editor.

If cursorObject doesn't return the "generated" var name (example: car1), but something like B Alpha 1-3:1, that probably means this variable is not correctly set.

Are you scripting for MP? (perhaps the var name is set locally, not broadcast)

What is the context for your "generated" var name? (a mod?, one of your script?)

What do you want to do with?

Share this post


Link to post
Share on other sites

Thank @Harzach , @Nemanjic, @pierremgi , for all these answers !

 

Actually it s for an usage when you didn  t set a custom var name and you want the one generated by the game , or for a newly created object by zeus or previewed by the splendid config viewer !

Here it s in SP for instance and directly using the eden console command.

Hazarch cursorObject call BIS_fnc_objectVar; works ! Nice !

 

So just a feedback cursorObject works only for vanilla vehicles and turrets for instance, for modded it returns this "B Alpha 1-3:1".
For Modded Vehicles "cursorObject call BIS_fnc_objectVar;" returns the correct "bis_o2" value !

Share this post


Link to post
Share on other sites

Just wanted to clarify something here.

 

In vanilla the game does not automatically assign objects to global variables unless they are given a variable name in the editor. Period

 

In short what happens behind the scenes when you give your object a name in the editor is this:

myVarName = _theObject;

_theObject setVehicleVarName "myVarName";

 

The first line assigns the reference to the global variable called "myVarName".

The second line sets the objects variable name ( a property in the object), this is what allows your object to show up as "bis_o2".

 

When you turn an object into a string (like when you but cursorObject inte the debug console and hit execute) the game reads the object's vehicleVarName and prints that. If that name isn't defined the game falls back on predetermined defaults depending on the type of object and its state, i.e. for an unit it prints the group/unit identification.

 

If you need an object to be assigned to a global var and have it's vehicleVarName set to the same then @Harzach's solution is the easiest way to go.

 

All BIS_fnc_objectVar does is look if the object has been given a name (either through editor or a previous call to BIS_fnc_objectVar)

If no name is assigned BIS_fnc_objectVar essentially performs the same steps as above.

 

So the TL;DR is: if you need to access "random" objects as a named one just use BIS_fnc_objectVar on it once and you are set.

 

  • Like 2

Share this post


Link to post
Share on other sites

OK. Thank for this detailled  clarificatiion @mrcurry !

So once you ve overite the original unit/group identifiation, because the game does not give any variable name at the begining, you cannot cahnge it afterwards.
Like you said, once you ve give it a new variable name and you cannot edit it afterwards with BIS_fnc_objectVar, it will be the new definitive variable name.

3 hours ago, mrcurry said:

All BIS_fnc_objectVar does is look if the object has been given a name (either through editor or a previous call to BIS_fnc_objectVar)

If no name is assigned BIS_fnc_objectVar essentially performs the same steps as above.

Copy.

Share this post


Link to post
Share on other sites
3 hours ago, ACI XCIX-0001 said:

So once you ve overite the original unit/group identifiation, because the game does not give any variable name at the begining, you cannot cahnge it afterwards.

 

No, not using BIS_fnc_objectVar, the purpose of that function is defined quite well in the description of the function: "Return a unique object variable. The variable is preserved after unit respawn."  - Note that the return is a string a.k.a. the set or read variable name.

It is possible to change it using setVehicleVarName however like so, though this is rarely needed as shown at the bottom.

myObject setVehicleVarName "someOtherName";

The main thing I wanted to highlight was the difference between vehicleVarName and a variable (global or otherwise).

Just because an object is given a vehicleVarName does not mean it is contained in the variable of the same name, or any variable for that matter.
A good example is provided on the BIKI for setVehicleVarName, see Example 1.
 

When working with more dynamic objects i.e. spawned during mission runtime I advocate working with the references more directly if possible.

An example of direct usage would be: 

// Execute "myScript.sqf" on object the cursor is pointing at, the reference to the object is return by cursorObject and is passed directly into the script
cursorObject execVM "myScript.sqf";



// Inside "myScript.sqf" params extracts the reference into the variable _myObject which can then be used for whatever we wish.
params ["_myObject"];

_myObject setDamage 1; // Example: destroy the object

or more simply:

cursorObject setDamage 1;

 

  • Like 1

Share this post


Link to post
Share on other sites

In MP, a step further:

apply on a local vehicle _veh (or even veh as global on one PC)
 

missionNamespace setVariable ["aStringedName", _veh, true];  // broadcast a variable referring to the vehicle
[_veh,"aStringedName"] remoteExec ["setVehicleVarName", 0, _veh];   // broadcast the setting of string representation of the vehicle to the string "aStingedName".

 

  • Like 1

Share this post


Link to post
Share on other sites

Thank you for your detailled answer @mrcurry.

19 hours ago, mrcurry said:

The variable is preserved after unit respawn."  - Note that the return is a string a.k.a. the set or read variable name.

So this means this means that as it doesen t change variable naming after "respawn", it doesen t change variable naming after executing "BIS_fnc_objectVar" as well.

19 hours ago, mrcurry said:

// Execute "myScript.sqf" on object the cursor is pointing at, the reference to the object is return by cursorObject and is passed directly into the script
cursorObject execVM "myScript.sqf";



// Inside "myScript.sqf" params extracts the reference into the variable _myObject which can then be used for whatever we wish.
params ["_myObject"];

_myObject setDamage 1; // Example: destroy the object

or more simply:


cursorObject setDamage 1;

OK. So when you "setVehicleVarName;", you actually just set a name for the variable but you don t set the variable itself until you "MyOffroad = _playersCar;", varible now stored, which you will find with "params ["_myObject"];" and then you can refer to it in other commands but you can also do it with just the name of the variable either it be the unit/group id or a variable name like "bis_o2".

Thank @pierremgi for your clarification about MP.
By the way do you have an answer concerning this post ? :

On 6/7/2023 at 11:14 PM, ACI XCIX-0001 said:

Nice ! Thank @pierremgi !
I will definitely try them and come back if needed !
So could you give a direct example of a piece of code to easily change the current camera mode on the current used player turret by the command console because apparently it only works with CamCreate ?

Share this post


Link to post
Share on other sites
21 hours ago, pierremgi said:

In MP, a step further:

Unless you are using BIS_fnc_objectVar as it does this for you as well.

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

×