Game Development Community

Console Methods not working

by Elizabeth Sweedyk · in Torque Game Engine · 06/14/2006 (11:50 am) · 5 replies

We're trying to add a new console method in shapebase.cs (so it can be accessed by anything with a shape). The idea is to make an array consisting of the "good guys" in our game, each member of which will be targetable by the AI. In shapebase.cs we put the following:

$GOOD_GUYS_PTR = 0;

function ShapeBase::goodGuysAdd(%this)
{
$GOOD_GUYS[$GOOD_GUYS_PTR] = %this;
$GOOD_GUYS_PTR++;
};

then, when a player is spawned, we call %player.goodGuysAdd(); in the file aijames.cs
This results in the console message:

perfectparent/server/scripts/aijames.cs (367): Unknown command goodGuysAdd.
Object (1747) AIJames -> Player -> ShapeBase -> GameBase -> SceneObject -> NetObject -> SimObject

How can we make this function accessible across the files?

#1
06/14/2006 (2:23 pm)
Please ignore the above.

It turns out that what we needed (for anyone having a similar problem) was to leave off the semicolon at the end of the function declaration.

We thought we needed to put on the semicolon after seeing the exact same syntax in the TorqueScript tutorials, so stay on your toes when reading the "Object Namespace Hierarchies" section...

http://www.garagegames.com/docs/tge/general/ch05s04.php
#2
06/14/2006 (2:35 pm)
Hehe, a typo. I would suggest trying TDN to find information like that, it's alot better. I don't know if the same article is over there, but in any case - glad you solved it! :D
#3
06/14/2006 (5:59 pm)
So you had to declare it as "function ShapeBase:goodGuysAdd(%this)"? Double-semi's have always worked for me, unless I'm not sure I understand your solution.
#4
06/14/2006 (6:39 pm)
: == Colon
; == semicolon

He was walking about the semicolon after the terminating curly brace. Those are only needed in datablock definitions AFAIK.
#5
06/14/2006 (9:05 pm)
A pedantic but important note: what you created was a Script Method, not a ConsoleMethod. ConsoleMethods are made in C++ via the ConsoleMethod macro.

And I'm glad you figured out your issue--semicolons are only needed after datablock scoping brackets and the new operator scoping body, not normal function scoping brackets.