Game Development Community

For real newbies - like me ;)

by Isidore · in Torque Game Engine · 07/12/2002 (4:10 pm) · 3 replies

I wanted to have some C/C++ code executed from the console.

If any other person meets the same problem as me.
here is how to do this (this is for real beginners like me. feel free to flame I don't minde :) )

add a .cc file like this to your torque project

///////////////////////////////////////////
// Declaration of a dummy console object //
///////////////////////////////////////////
#ifndef _CONSOLEOBJECT_H_
#include "console/consoleObject.h"
#endif

typedef ConsoleObject Parent;

class my_console_object : public ConsoleObject
{
public:
  static void consoleInit();

   DECLARE_CONOBJECT(my_console_object);
};

//////////////////////////////////////////////////////////////////////////
// Declaration of the static functions we want to call from the console //
//////////////////////////////////////////////////////////////////////////
void my_console_func(SimObject*,S32 my_s32,const char** argv);

////////////////////////////////////
// Initializing the console object //
////////////////////////////////////
IMPLEMENT_CONOBJECT(my_console_object);

void my_console_object::consoleInit()
{
  // Define a console command
  Con::addCommand(
    "console_func",   // the function name in the console
    my_console_func,  // real name of the function
    "text",           // text displayed if the function is called with invalid number of arguments from the console 
    1,                // minimal number of arguments (including the SimObject*  parameter)
    2                 // maximal number of arguments
  );
}

///////////////////////////////////
// Code for our static functions //
///////////////////////////////////
void my_console_func(SimObject* my_sim_object,S32 argc,const char** argv)
{
  // get arguments
  if ( argc == 2 ) { // if there is one argument
    const char* my_argument=argv[1];
  }

  // now, do whatever we want in this static function
  int a=9; // here, a simple step in the debugger
} 

/////////
// end //
/////////

this makes the code executable of my_console_func() from console and script by typing console_func();

This will probably help nobody, but just in case... Besides, it took me time to find how to do that basic thing (^_^;)

#1
07/16/2002 (4:24 pm)
A good example. Maybe post this as a resource. I sure could've used this when I was new to Torque.
#2
07/17/2002 (12:36 pm)
Well... I think that you've just lost your newbee status...

If you can figure that out, you're a lot less new than I am...

Good hacking, thanks for sharing it.

--Mike
#3
07/20/2002 (8:17 am)
Hi!

Mike, if you think my post might be useful, I'll try and submit is as a resource (but I make no illusion concerning its rating :D).

and good luck to you Michael!

This engine sure takes time to be understood :( .
I am still trying to figure how how to use it efficiently, and I try and post the tricks I discover little by little.

Anyway I am sure we'll both manage, eventually :)

Thanks you both for having read my post anyway!

Cheers,

Laurent