Finding simObjects by name, from script.

Expanding and utilizing the engine via C++.
7 posts Page 1 of 1
chriscalef
Posts: 375
Joined: Mon Feb 09, 2015 7:48 pm
by chriscalef » Tue Nov 28, 2017 6:15 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. :-)
Jason Campbell
Posts: 268
Joined: Fri Feb 13, 2015 2:51 am
 
by Jason Campbell » Wed Nov 29, 2017 12:27 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/r ... imSet.html
chriscalef
Posts: 375
Joined: Mon Feb 09, 2015 7:48 pm
by chriscalef » Wed Nov 29, 2017 4:25 am
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.
OTHGMars
Posts: 17
Joined: Fri Jul 14, 2017 2:19 am
by OTHGMars » Wed Nov 29, 2017 11:02 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?
JeffR
Steering Committee
Steering Committee
Posts: 816
Joined: Tue Feb 03, 2015 9:49 pm
 
by JeffR » Wed Nov 29, 2017 3:49 pm
Yeah, @
User avatar
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.
chriscalef
Posts: 375
Joined: Mon Feb 09, 2015 7:48 pm
by chriscalef » Thu Nov 30, 2017 3:33 am
Ah, right, duh! That makes perfect sense. Thank you @
User avatar
OTHGMars
@
User avatar
JeffR
JeffR
Steering Committee
Steering Committee
Posts: 816
Joined: Tue Feb 03, 2015 9:49 pm
 
by JeffR » Sat Dec 02, 2017 2:52 am
Any time :)
7 posts Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests