chriscalef Posted November 28, 2017 Share Posted November 28, 2017 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?? 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. :-) Quote Link to comment Share on other sites More sharing options...
Jason Campbell Posted November 28, 2017 Share Posted November 28, 2017 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 Quote Link to comment Share on other sites More sharing options...
chriscalef Posted November 29, 2017 Author Share Posted November 29, 2017 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. Quote Link to comment Share on other sites More sharing options...
OTHGMars Posted November 29, 2017 Share Posted November 29, 2017 In that case:%name = "SomeName"; %objID = findSimObjectByName (%name); would be functionally equivalent to:%name = "SomeName"; %objID = isObject(%name) ? %name.getId() : 0; or, if you want to restrict it to being a member of a particular SimSet. %name = "SomeName"; %objID = SomeSet.isMember(%name) ? %name.getId() : 0;Is there a particular case where a dedicated function would be preferable? Quote Link to comment Share on other sites More sharing options...
JeffR Posted November 29, 2017 Share Posted November 29, 2017 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. Quote Link to comment Share on other sites More sharing options...
chriscalef Posted November 30, 2017 Author Share Posted November 30, 2017 Ah, right, duh! That makes perfect sense. Thank you @OTHGMars @JeffR Quote Link to comment Share on other sites More sharing options...
JeffR Posted December 2, 2017 Share Posted December 2, 2017 Any time :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.