Jump to content
Sign in to follow this  
m0nkey

How to convert nearestObject to work with getText ?

Recommended Posts

I've looked for the answer here and with search engines. I'm not even sure what you call it really.

nearestObject or any similar command might return a value such as

305cc800# 39619: i_barracks_v2_f.p3d

Since this value is usually in a variable or an array, you can reference it as an object (ie. getPos variableName). Its a usable thing which is nice. You can also reference it by the # (ie 39619) which can also be useful.

But I've recently tried to get the "display name" from the config file for specific types of nearObjects (ie like military structures). So, this value is returned, but is not usable in

_text = getText (configFile >> "CfgVehicles" >> str(myVar) >> "displayName");

If you don't str() the variable, you get an error of expecting string but providing object (obvious fix). If you str() it, you get nothing returned. I would assume the getText function really wants the config name (ie Land_I_Barracks_v2_f). Display name is present for that.

Is there a way to use the returned value from nearObject with getText or getArray, or configFile>> stuff in general? String manipulation is, well, there really isn't any in this script language otherwise I might just have manipulated the strings myself and been done with it.

Thanks for any help.

EDIT: Posted too soon I guess. The answer is to use typeOf

_text = getText (configFile >> "CfgVehicles" >> (typeOf (_array select 0)) >> "displayName");

So if you are using nearObject or nearestObjects and you wish to have a usable text name to display to the users for some reason, this will get that normal display name into a variable (or whatever you want).

Answer actually was obvious if I had been thinking properly. Sorry for the post, maybe it will help someone else out in the future.

Edited by m0nkey

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  

×