### Finding simObjects by name, from script.

Expanding and utilizing the engine via C++.

#### Finding simObjects by name, from script.

chriscalef
Posts: 347
Joined: Mon Feb 09, 2015 7:48 pm
So, I recently wrote an engine function to do this, but felt awfully stupid because there *has* to be a way to do this already, right??

Code: Select all

DefineEngineFunction(findSimObjectByName, S32, (const char *objName), , ""){   SimObject *simObj = NULL;   simObj = Sim::findObject(objName);   if (simObj)      return simObj->getId();   else      return 0;}

I looked around in simSet and SimGroup but couldn't find anything. In case this is actually lacking in the engine, could someone give me a better idea of where it should live? I know where I put it is the wrong place, that's all I know.

#### Re: Finding simObjects by name, from script.

Jason Campbell
Posts: 221
Joined: Fri Feb 13, 2015 2:51 am

What about findObjectByInternalName()? Every SimObject would have to have an internal name but it can search SimGroups and SimSets. Think it is game.cs where this would go.

http://docs.garagegames.com/torque-3d/reference/classSimSet.html

#### Re: Finding simObjects by name, from script.

chriscalef
Posts: 347
Joined: Mon Feb 09, 2015 7:48 pm
Well, yeah I've been using that for a while, but it just seems silly not to have a script way to find any object in the scene by its declared name. I wonder if simManager.cpp would be a reasonable place to put it, if it actually isn't already somewhere.

#### Re: Finding simObjects by name, from script.

OTHGMars
Posts: 2
Joined: Fri Jul 14, 2017 2:19 am
In that case:

Code: Select all

%name = "SomeName";%objID = findSimObjectByName (%name);

would be functionally equivalent to:

Code: Select all

%name = "SomeName";%objID = isObject(%name) ? %name.getId() : 0;

or, if you want to restrict it to being a member of a particular SimSet.

Code: Select all

%name = "SomeName";%objID = SomeSet.isMember(%name) ? %name.getId() : 0;

Is there a particular case where a dedicated function would be preferable?

#### Re: Finding simObjects by name, from script.

JeffR
Steering Committee
Posts: 783
Joined: Tue Feb 03, 2015 9:49 pm

Yeah, @
OTHGMars
is correct. Technically the name ITSELF is a reference in script. Unlike in C++ where you need to actually talk to the console to find an object by name, the name itself is a reference to the object. If you have the object, and the object exists, you're done.

If your object is called TheThing in the level, then if you know the object's name (TheThing) then accessing it is as simple as using it's name TheThing.variable = 5;

If you're unsure if it exists yet, then you can use isObject(TheThing) to validate that an object with that name exists first.

Having said that, There could indeed be use in a function that lets you search partial names and get back an object, or a list of objects. That could be pretty handy.

#### Re: Finding simObjects by name, from script.

chriscalef
Posts: 347
Joined: Mon Feb 09, 2015 7:48 pm
Ah, right, duh! That makes perfect sense. Thank you @
OTHGMars
@
JeffR

#### Re: Finding simObjects by name, from script.

JeffR
Steering Committee
Posts: 783
Joined: Tue Feb 03, 2015 9:49 pm

Any time

#### Who is online

Users browsing this forum: No registered users and 1 guest