Using new classes
by Terry Kingston · in RTS Starter Kit · 04/28/2005 (9:03 pm) · 3 replies
I set up a new class for the npc chars in my game called NPC.
then i made a file called NPCAI.cs here is the start of it...
function NPC::onAdd(%this)
{
%location = %this.getPosition();
if(%location)
echo("location = " @ %location);
}
i just set up a basic function to test it. but i get this error in the console...
starter.RTS/server/scripts/avatars/NpcAI.cs (14): Unknown command getPosition.
Object riflemanBlock(53) riflemanBlock -> NPC -> RTSUnitData -> PlayerData -> ShapeBaseData -> GameBaseData -> SimDataBlock -> SimObject
i dont understand why it doesnt know what the funciton is...
btw i just added the following field in the rifleman datablock. everything else is original RTS SK code.
ClassName = "NPC"
im still a newb so i need help :/
then i made a file called NPCAI.cs here is the start of it...
function NPC::onAdd(%this)
{
%location = %this.getPosition();
if(%location)
echo("location = " @ %location);
}
i just set up a basic function to test it. but i get this error in the console...
starter.RTS/server/scripts/avatars/NpcAI.cs (14): Unknown command getPosition.
Object riflemanBlock(53) riflemanBlock -> NPC -> RTSUnitData -> PlayerData -> ShapeBaseData -> GameBaseData -> SimDataBlock -> SimObject
i dont understand why it doesnt know what the funciton is...
btw i just added the following field in the rifleman datablock. everything else is original RTS SK code.
ClassName = "NPC"
im still a newb so i need help :/
About the author
#2
that data block thing does make alot of sense. Im going to try it that way and see if i can get it to work...
i think my original post was kinda hard to understand. it was late and i had almost pulled all of my hair out.
just to restate it more simply:
I know it IS using the onAdd function. I just don't know why it wont use the getPosition(). i also tried the getDataBlock() funciton
it wont use that one either. It does, however, use other functions like getID() (but it does it wierd, there are 6 rifleman and getID() gives
me the number 53 6 times. insead of their unique handles. unless i dont understand how that one is supposed to work.)
anyhow. i guess ill go wrench on it for a bit..
any help is much appreciated.
04/29/2005 (9:40 am)
Hehe. thanks for trying though. that data block thing does make alot of sense. Im going to try it that way and see if i can get it to work...
i think my original post was kinda hard to understand. it was late and i had almost pulled all of my hair out.
just to restate it more simply:
I know it IS using the onAdd function. I just don't know why it wont use the getPosition(). i also tried the getDataBlock() funciton
it wont use that one either. It does, however, use other functions like getID() (but it does it wierd, there are 6 rifleman and getID() gives
me the number 53 6 times. insead of their unique handles. unless i dont understand how that one is supposed to work.)
anyhow. i guess ill go wrench on it for a bit..
any help is much appreciated.
#3
Object riflemanBlock(53) riflemanBlock -> NPC -> RTSUnitData -> PlayerData -> ShapeBaseData -> GameBaseData -> SimDataBlock
In your function, %this is the ID for the dataBlock, you need to add a %obj variable to the header, and use it with .getPosition().
04/29/2005 (7:22 pm)
The error does say what the problem is. You are trying to call the getPosition() method on a dataBlock, and not an object instance.Object riflemanBlock(53) riflemanBlock -> NPC -> RTSUnitData -> PlayerData -> ShapeBaseData -> GameBaseData -> SimDataBlock
In your function, %this is the ID for the dataBlock, you need to add a %obj variable to the header, and use it with .getPosition().
Torque Owner Ishbuu
Hope I can help ya, so here goes. This won't work because whenever you do an "::onAdd()", you need the object which is being added to be a datablock or a datablock type. Yeah... examples...
This is correct:
function RTSUnitData::onAdd(%this, %obj) { echo("RTSUnitData::onAdd called."); }The above works because "RTSUnitData" is a type of datablock...Now for another example - This is assuming that "UnitBaseBlock" is an existing datablock...
function UnitBaseBlock::onAdd(%this, %obj) { echo("UnitBaseBlock::onAdd called."); }THIS works because "UnitBaseBlock" is an existing object. Since "UnitBaseBlock" is part of "RTSUnitData" one might think there would be a conflict, but there isn't (thank god...) which allows you to make specific code for that unit type :)Now that I've finished my tiny little lesson, to make what you want work you would maybe put an if statement inside the RTSUnitData on add function, or write a custom onAdd function for each of the units. Hope I helped some :)
EDIT: Ah well after re-reading your post i figured out what you wanted *sob* so here's whats your problem. You're calling the getPosition, but you're calling it on the %this variable. For onAdd, two variables are passed... (Thought it was three... oh well...) %this and %obj are the two variables. Lets hope this is right: %obj is the player, %obj.client is the client, and %this is... I dunno :) I'm pretty sure you would call "%obj.getPosition" - someone correct me...