Game Development Community

C++ Integration

by Andrey-Gr · in Torque Game Builder · 12/01/2011 (11:24 pm) · 3 replies

Hello!
I'm beginner with TGB, could someone please explain how can I integrate my C++ code with TGB, I already read couple of tutorials "Fill Battle" for example but still this is not clear for me.

In my C++ code I have some basic game entities, FSM and text output :),
question is how can I control scene objects through my C++ code?
The first thing I want to do is simply output text from my FSM into the "Text Object" in my scene file, please point me, how can I do such thing?

#1
12/02/2011 (7:58 am)
If you've named your text object, you can use Sim::findObject("textObjectName"). (NOTE: I'm not at my computer, so I don't have access to the source code to make sure this is right.)

You can then cast that to a t2dTextObject (or whatever class it is). Then you can use the standard C++ functions (like .setText) to set the text in the C++ code.
#2
12/05/2011 (11:10 am)
I went and double-checked and that's definitely it. So, if you want your C++ FSM to write text into a text object, use

t2dTextObject *ctrl = dynamic_cast<t2dTextObject *>(Sim::findObject("FSMTextObject"));
if( ctrl )
  ctrl->setText( "Your text goes here..." );

Just make sure that you've set the name of your text object to "FSMTextObject" in the TGB editor.
#3
12/05/2011 (11:45 pm)
Great!
Thank you so much!