Game Development Community

Simple Console Method Call?

by Paul /*Wedge*/ DElia · in Torque Game Engine · 05/10/2005 (10:30 am) · 20 replies

I've tried adding a console method and calling it in a source function in staticshape.cc, as a simplyer way for me to have optional script access to the processTick method (since I'd much rather write my custom behaviours there). I confirmed the boolean check in processTick is checking, and that the method is defined anc can be called from script properly, but I can't get the method to call from inside processTick... I'm thinking it's an improper reference for the function, but mDataBlock (or getDataBlock()) are the only references I can find that make any sense. Perhaps it should be referencing the object and not the datablock, but I'm not sure how to do that? I'll see if I can post the code, though the forum seems to be yelling at me when I try that?

#1
05/10/2005 (1:18 pm)
I'm a little unclear what you're trying to do. Can you try explaining again?
#2
05/10/2005 (5:40 pm)
If it'd just let me post the code...

http://upl.silentwhisper.net/uplfolders/upload9/consolecode.txt

Woo! That'll work for now.... errr for getting the code posted that is, it still doesn't work.
#3
05/10/2005 (7:02 pm)
Are you trying to call from C++ to script? If so, you don't need to define a ConsoleMethod; that just exposes functionality to the scripting language.
#4
05/10/2005 (7:19 pm)
Yes I want a script exposed method that is called in ProcessTick so I can set behaviours in script that are called on every tick in an object. Basically an optional scriptside ProcessTick method. If I got this working I might just move it up to GameBase as a generic property like the scriptside onAdd and such.
#5
05/10/2005 (10:00 pm)
Ok, what you are looking for then is the command Con::executef. The parameters are: c++ object that the function is called on, the number of parameters (including the script name), and optional params:

Con::executef(myObject, 3, "myScriptCallback", optionalParam1);
#6
05/10/2005 (10:10 pm)
Yes I know that, but however I have that setup doesn't seem to be working, and I can't figure out why. It's not getting any errors, but it's not calling the function either... the source code is in that link... the forums are giving me this weird error when I try to post it in the thread... wat are the brackets for posting code here?
#7
05/12/2005 (6:02 pm)
Known site issue, we'll get it fixed eventually. :)

Have you tried single stepping through the code to identify where it's going wrong?
#8
05/12/2005 (9:22 pm)
I went up to gamebase and got it working there, I think the problem was I was creating the console method on the object instead of the datablock, and I didn't know how to reference the object in the Con::executef function. I defined the method on the datablock and could call it fine and it seems to be working okay now. The only thing I don't get is that I can't call the function in processTick in GameBase, I guess because that's where it's initialized? Anyway, yeah I've more or less got what I want now I think.
#9
05/13/2005 (4:32 am)
What is the best way to get started? I'm new at this.
#10
05/13/2005 (7:05 am)
Get started... with... what?
#11
05/24/2005 (4:30 am)
I'm not sure. What are the different development tools you need to start making your game? Right now i only have Eclipse. Can you make games in Eclipse?
#12
05/24/2005 (7:24 am)
@Aaron, Do a search on this site for TBE

@Paul, code blocks are defined with [ code ] code goes here [ /code ]
For URLs and Images just use URL or IMAGE rather than code.
#13
05/24/2005 (7:31 am)
Yeah that's what I thought... it's an issue with the new forums that was breaking stuff... wonder if it'll work now...

ConsoleMethod(StaticShape, laserCheck, void, 2, 2, "()" "Script process tick callback")
{
	Con::errorf("Calling laser Check");	
}
 
void StaticShape::processTick(const Move* move)
{
   Parent::processTick(move);
 
   if(mDataBlock->isLaserTrip) {
   	     //Con::errorf("Datablock is %s", );
	   	 Con::executef(mDataBlock,2,"laserCheck",scriptThis());
   }

Oh good forums are working now... an' that's not the code I ended up using, but yeah, just wanted to test that.
#14
05/24/2005 (2:44 pm)
@Dreamer, i have TBE installed onto my computer, and after i installed it the Eclipse program appeared on my desktop. And when i bring up the torque engine source code it does nothing but show the source code. In other words, i don't know how to use the source code to make video games. Do i need any other tools than TBE?
#15
05/24/2005 (3:18 pm)
TBE is simply a minimal IDE (Integrated Development Environment) that is primarily used for managing a "project". You use it to define what gets compiled when you want to compile your code.

To modify files (either C++ source code, or script files), you will want a text editor...anything from notepad all the way up to commercial text editors work fine.

I would absolutely suggest to you that you look into purchasing the (print) book "3D Game Programming All in One" by Ken Finney. It steps you through a large spectrum of topics regarding making games, and uses Torque for it's (development) demonstration engine. You can purchase the book in a variety of places, from a local (large) book store, to Amazon.com, as well as here at GarageGames!

And just a little forum adminstrative suggestion: It's best not to jump into someone's thread with an off-topic question, because it tends to distract the conversation, and confuse people that come to read the thread later. Many people will use the google search engine (see the Search button in the yellow menu bar above), and search to see if anyone has asked a similar question, and/or make your own post in the appropriate area.
#16
05/24/2005 (3:55 pm)
Ok, sorry
#17
05/24/2005 (5:17 pm)
Con::executef(mDataBlock,2,"laserCheck",scriptThis()); --- wouldn't that call the DATABLOCKS laserCheck function? I am unsure.
#18
05/24/2005 (5:40 pm)
Yes, it would, and would pass an ObjectID as the second parameter to that call. So in this case, the actual script method would need to look like:

XXXData::laserCheck(%this, %object)
{
// %this is an ObjectId for the datablock, and %object is an ObjectId for the actual instantiation of the object
....implementation....
}

and would work on an object that was defined like:

%myObject = new(XXXData) {
....implementation....
}

Remember that he mentioned above that he didn't actually use the specific code displayed, but for those recently reviewing the thread as a whole, there is actually a logic issue with how he has things setup in the example above:

In his ConsoleMethod he defines the interface (how the method is called) to be based upon a StaticShape object, with zero additional parameters. However, in his process tick method, he calls the method laserCheck on the datablock of the object, and passes an ObjectId to the object as the first parameter.

Another thing to keep in mind is that when you execute Con::executef(...), it does not use the ConsoleMethod handle (that's only for exposure for scripted calls, not engine source code calls), but calls the script implementation directly at the console.

From another angle, a ConsoleMethod is a way for script to call engine implementation, while Con::executef(...) is a way for engine code to call a script implementation.
#19
05/25/2005 (1:05 am)
Yeah it was calling the datablock, one reason why it wasn't working... and yes the parameters were off as well, hence why I ended up with this:

ConsoleMethod(GameBaseData, scriptTick, void, 3, 3, "GameBase g" "Script process tick callback")
{
	//Con::errorf("Calling script Tick");	
}

void GameBase::scriptOnTick()
{
   if (!isGhost()){   	
      Con::executef(mDataBlock,2,"scriptTick",scriptThis());
   }
}
#20
05/25/2005 (4:26 pm)
Thanks for posting the modifications!

I do want to point out however that it still appears that you think ConsoleMethods and Con::executef() are related--they are not :) In fact, they are exact opposites--you can write one without the other, and do so if you have a need to have script call engine or engine call script, without the other, opposite "direction" call capability.