Torr Posted June 29, 2017 Share Posted June 29, 2017 I'm new of Torque3DLooking the source to understand how to expose function to c-script I found these: DefineEngineFunction, ConsoleFunctionCan you please confirm me if I've understood well?With DefineEngineFunction the function exposed can be called either on console and c-script but when the console is removed / dropped this function is available only for c-script.With ConsoleFunction the function is available either on console and c-script but when the console is removed / dropped the function cannot be accessed by none of the two.How can I drop the console to make a test? Quote Link to comment Share on other sites More sharing options...
LukasPJ Posted June 30, 2017 Share Posted June 30, 2017 I'm not entirely sure what you mean with "dropping the console".ConsoleFunctions is, essentially, a deprecated version of DefineEngineFunction. They serve the same purpose, DefineEngineFunction is simply a bit more sophisticated, and allows for typing declaration of the function (maybe more?).As far as I know, DefineEngineFunction actually uses ConsoleFunction internally. Quote Link to comment Share on other sites More sharing options...
Torr Posted June 30, 2017 Author Share Posted June 30, 2017 Oh, Thanks you! I've understood the wrong thing by reading the code documentation.So each function, object, class that is exposed to c-script is also available to console? Quote Link to comment Share on other sites More sharing options...
Torr Posted June 30, 2017 Author Share Posted June 30, 2017 I've created this class: class MyFirstClass : public ConsoleObject { public: typedef ConsoleObject Parent; public: String mName; public: DECLARE_CONOBJECT(MyFirstClass); MyFirstClass(); static void initPersistFields(); }; And I want init an object of it using c-script, so i written:%firstObject = new MyFirstClass(); %firstObject.name = "Text written from .cs file"; echo(%firstObject.name); but I get an error that says this I need inerith from SimObject. I attached a screenshot with the full error text.How can I Init this object in c-script?How can I Init an object in c++ and register its pointer to the memory manager? Quote Link to comment Share on other sites More sharing options...
Happenstance Posted June 30, 2017 Share Posted June 30, 2017 Your code looks fine as far as I can tell but inheriting from SimObject (or even lower, to SceneObject or GameBase) is typically what you want to do. The only classes in the engine that inherit from ConsoleObject are SimObject and NetEvent, neither of which are meant to be instantiated directly from script.This was written for an older version of Torque but is still (mostly) relevant and might be of use to you:Class Hierarchy - ConsoleObject Quote Link to comment Share on other sites More sharing options...
Torr Posted June 30, 2017 Author Share Posted June 30, 2017 Thanks for this information, but if the ConsoleObject cannot be instantiated, why they put "Console" in the name?What stand this name SimObject?Since I can't find nothing about memory management or Garbage collector, This engine uses a memory system or it's demand to the programmer to manage it?If you know, specify it for either c++ and c-script please. Quote Link to comment Share on other sites More sharing options...
Happenstance Posted July 1, 2017 Share Posted July 1, 2017 The point of ConsoleObject is just to define some basic functionality required to interface with the console/scripting system. SimObject inherits from ConsoleObject but adds additional required functionality. simObject.h explains this is more detail. I think it used to be possible (waay back in the early TGE days) to instantiate a ConsoleObject directly but that's no longer the case. If you look at line 869 in compiledEval.cpp you'll see why you get an error.As far as memory management, TorqueScript isn't garbage collected and there's no concept of new'd objects going out of scope, so it's possible to leak memory if you're not careful. Few examples to demonstrate: // $myObj is a global var that stores the 'SimId' mapped to MyFirstObject() // I can reference $myObj from any script $myObj = new MyFirstObject(); // But if I remap $myObj to something else... $myObj = "Oh no!"; // Then I've essentially created a memory leak: MyFirstObject() is still exists but I have no reference to it function CreateObject() { // %myObj is a local var that stores the 'SimId' mapped to MyFirstObject() // The %myObj variable will be destroyed when the function goes out of scope, but MyFirstObject() will still exist... %myObj = new MyFirstObject(); } function CreateObject() { // %myObj is a local var that stores the 'SimId' mapped to MyFirstObject() // The %myObj var will be destroyed when the function goes out of scope, but MyFirstObject() will still exist... // However, I've also given MyFirstObject() a name this time: 'MyObject' that I can reference anywhere - memory leak averted! %myObj = new MyFirstObject(MyObject); %myObj.doStuff(); MyObject.doStuff(); } %myObj.doStuff(); // will cause a console error - %myObj not found MyObject.doStuff(); // no error Quote Link to comment Share on other sites More sharing options...
Torr Posted July 1, 2017 Author Share Posted July 1, 2017 Thanks for this, since the doc is not so wide, expecially for c++ part, this thread is very important. Now I'm looking on how to instantiate a mesh, so I looked at player class.Do you have a link where is explained how to instantiate it? Or the only way is to check the current existent classes? Thanks!! Quote Link to comment Share on other sites More sharing options...
Happenstance Posted July 1, 2017 Share Posted July 1, 2017 Typically the two renderable classes you'll work with are TSStatic (a lightweight static mesh class with basic support for animations, collision, etc.) and StaticShape (like TSStatic but with much more functionality, including datablock support). TSStatic is usually used for static scenery objects like buildings, etc. StaticShape tends to be used for gameplay objects like CTF flags, doors, etc.There are also examples in the engine that explain how to create your own class that renders a mesh and uses a datablock. See the renderMesh, renderObject, and renderShape.cpp/h files for more on those. Quote Link to comment Share on other sites More sharing options...
Torr Posted July 3, 2017 Author Share Posted July 3, 2017 I searched for the examples, on google and on git-hub, but I've not found nothing. Can you please give me the link to these? Quote Link to comment Share on other sites More sharing options...
Timmy Posted July 3, 2017 Share Posted July 3, 2017 I searched for the examples, on google and on git-hub, but I've not found nothing. Can you please give me the link to these? https://github.com/GarageGames/Torque3D/search?utf8=%E2%9C%93&q=RenderMeshExample Quote Link to comment Share on other sites More sharing options...
JeffR Posted July 10, 2017 Share Posted July 10, 2017 Here's the specific documentation bit that pertains to that console initialization stuff:https://github.com/GarageGames/Torque3D/blob/a858fa775f9a96123a56cd66b302fd92d04ef0c5/Engine/source/console/consoleObject.h#L101-L197So while you look good on the header side of things for the declaration of the class object, you'll also want to have the IMPLEMENT_* macro in your cpp file for when you define all the functions and stuff. There's two macros to use IMPLEMENT_CONOBJECT and IMPLMENENT_CO_NETOBJECT_V1you use the NETOBJECT stuff in the event you need this class to be ghostable down to the client. If you use the regular conobject stuff, it'll only exist where you create it(create it on the server, it exists only on the server, no clients are aware of it, etc). 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.