Creating an object inherited from AIPlayer
by Harley · in Torque Game Engine · 06/12/2005 (1:05 am) · 13 replies
What I want to do is create some AIPlayer objects for my game but I need their functions to perform different things, ie I might want to have a function called AIPlayer::move but each type of enemy I have might do something different when it moves. I tried doing the below code but I got an error "Unknown command Test":
//This works fine
$testEnemy = new AIPlayer(MyEnemy)
{
datablock = dbEnemy1;
};
//This causes an error
$testEnemy.Test();
//This function never gets called
function MyEnemy::Test()
{
error("Test function");
}
Any suggestions as to what I am doing wrong?
Thanks for your help,
Harley.
//This works fine
$testEnemy = new AIPlayer(MyEnemy)
{
datablock = dbEnemy1;
};
//This causes an error
$testEnemy.Test();
//This function never gets called
function MyEnemy::Test()
{
error("Test function");
}
Any suggestions as to what I am doing wrong?
Thanks for your help,
Harley.
#2
06/13/2005 (1:18 pm)
I think the problem here is that you try to execute a function before it is defined. Move the call to Test() below the function definition and you should be in business
#3
@ Mark - I thought you were right on the mark then! But then I realised that I had already tried that hehe (I was shattered!). I gave it another go just in case and I got this error: (164): Unable to instantiate non-conobject class MyEnemy (I dont even get to try the test() function). if you have a look at this resource http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=5516 and go to the BasicObject::OnAdd function. It mentions in here that a valid namespace for the object is required. I think this may be missing from the AIPlayer object? Can someone varify this at all? Going by that resource I should be able to do %obj = new AIPlayer(MyEnemy) and then create functions for the MyEnemy object (if I read it correctly).
@Owen - unfortunately I dont think it is that easy as it errs before it even gets to that part of the script - bugger!
If anyone can shed any light on the namespace possibility it would be muchly appreciated.
Harley.
06/14/2005 (1:47 am)
Thanks for the suggestion guys.@ Mark - I thought you were right on the mark then! But then I realised that I had already tried that hehe (I was shattered!). I gave it another go just in case and I got this error: (164): Unable to instantiate non-conobject class MyEnemy (I dont even get to try the test() function). if you have a look at this resource http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=5516 and go to the BasicObject::OnAdd function. It mentions in here that a valid namespace for the object is required. I think this may be missing from the AIPlayer object? Can someone varify this at all? Going by that resource I should be able to do %obj = new AIPlayer(MyEnemy) and then create functions for the MyEnemy object (if I read it correctly).
@Owen - unfortunately I dont think it is that easy as it errs before it even gets to that part of the script - bugger!
If anyone can shed any light on the namespace possibility it would be muchly appreciated.
Harley.
#4
This works fine for me
06/14/2005 (1:27 pm)
So you tried chaging your code to:$testEnemy = new AIPlayer(MyEnemy)
{
datablock = dbEnemy1;
};
function MyEnemy::Test()
{
error("Test function");
}
//cant call the function until it is defined
$testEnemy.Test();This works fine for me
#5
06/15/2005 (4:54 am)
@ owen - no. I just entered this code in then and it doesn't work - it says it cant find the Test() function (I have positioned the code exactly as you have). I have found a work around using datablocks but its pretty messy. Can anyone else confirm whether the above code works/doesn't work for them? This seems a little strange and even more annoying now that it works on someone elses pc...
#6
06/15/2005 (10:53 am)
Have you tried this on a stock TGE build, minus all your customizations (if any)?
#7
-allowing Item objects to be affected by physical zones
-created a new object (basically copied and pasted the Item class, more for educational purposes)
-Added ItemObjectType to the player collision mask
Surely theses wouldn't affect what I am trying to do? I also tried doing the exact same thing with the ShapeBase class but I get the same error. I am using 1.3.
06/16/2005 (4:21 am)
Nah I haven't, but these are the only customisations I have made to the engine:-allowing Item objects to be affected by physical zones
-created a new object (basically copied and pasted the Item class, more for educational purposes)
-Added ItemObjectType to the player collision mask
Surely theses wouldn't affect what I am trying to do? I also tried doing the exact same thing with the ShapeBase class but I get the same error. I am using 1.3.
#8
It can be very difficult to "guess" if a particular implementation is being affected by other implementations, so one of the troubleshooting techniques is to implement it against stock torque--that way, we can help more directly because we both know that this is the only change you have made.
Also:
Enteres this code in where? The console directly? Or did you type it into a file and re-run torque to load in the file. Entering things into the console directly places each line into it's own scope, and that can throw things off drastically with multi-line inputs.
06/16/2005 (5:34 am)
I think what Mark is pointing out is a very important debugging step: isolating the issue. It can be very difficult to "guess" if a particular implementation is being affected by other implementations, so one of the troubleshooting techniques is to implement it against stock torque--that way, we can help more directly because we both know that this is the only change you have made.
Also:
Quote:no. I just entered this code in then and it doesn't work - it says it cant find the Test() function (I have positioned the code exactly as you have).
Enteres this code in where? The console directly? Or did you type it into a file and re-run torque to load in the file. Entering things into the console directly places each line into it's own scope, and that can throw things off drastically with multi-line inputs.
#9
BTW I entered this in a script file.
thanks.
06/17/2005 (4:07 am)
Fair enough. I will try this on stock Torque and see how i go. I am willing to try anything!BTW I entered this in a script file.
thanks.
#10
06/17/2005 (4:19 am)
Ok I can now say that I have tried this on a "stock" version of Torque (i moved my existing code to another folder and reinstalled the sdk) using the below code in a script file and it doesn't work either:datablock PlayerData(dbEnemy1)
{
shapeFile = "~/data/shapes/player/player.dts";
};
$testEnemy = new AIPlayer(MyEnemy)
{
datablock = dbEnemy1;
};
function MyEnemy::Test()
{
error("Test function");
}
$testEnemy.Test();
#11
06/17/2005 (10:51 am)
What do you get from $testEnemy.dump()?
#12
06/17/2005 (8:16 pm)
I get the usual list of functions that you would expect from the AIPlayer class (no Test() function). If you want me to paste the list just let me know.
#13
The script namespaces dot point is what I am interested in. As none of you guys seem to be having this problem I am wondering if I (somehow) have an older version of the AIPlayer source files? I just can't figure out why, even on the stock version, I am having trouble when no one else is...
06/17/2005 (10:00 pm)
Hmmm I found this thread . About a quarter of the way down Pat Wilson writes:Quote: Errr...geez I keep getting called onto the carpet for these AI threads. Here's the plan at the moment. Yes, you can now have bots running about, and I should probably do a waypoint type demo with that script instead of just echos. This is what I need to do:
-Better demo script
-Script namespaces (So you can have different AI classes instead of just the AIPlayer script handlers)
-AI Objects, not players. Players take up lots more server resources then is really needed, they also take up a player slot.
-*sigh* Pathfinding. I wrote about my ideas for the pathfinding in my last .plan but so far I haven't worked on it.
I will try to get to it, however, the script interface probably won't change too much, if at all. So when you do a setMoveDestination, when pathfinding is in, it will pathfind to that destination, where as right now it just does a straight line.
The script namespaces dot point is what I am interested in. As none of you guys seem to be having this problem I am wondering if I (somehow) have an older version of the AIPlayer source files? I just can't figure out why, even on the stock version, I am having trouble when no one else is...
Torque Owner Mark Storer
I wasn't sure of the answer myself, so I did some digging... and found the answer HERE: www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=2212
Specifically, if you scroll down to the "Other Object Creation" section, the second piece of sample code reads:
new class_expression(name_expression : copy_source_identifier) { initialization_statements };Do you see what you did wrong?
You created an AIPlayer NAMED MyEnemy. What you want is a MyEnemy that inherits everything from AIPlayer... which IF I'm right, looks something like:
$testEnemy = new MyEnemy( someBaddy : AIPlayer ) { datablock = dbEnemy1; } $testEnemy.Test();And if THAT doesn't work, I suggest you try "$testEnemy.dump()". It'll show all the available methods and members of $testEnemy.
This raises an interesting question: Does an object REQUIRE a name? Can you do this:
EDIT: formatting