Game Development Community

Help with Unknown command getCount

by Greg Deutschlander · in General Discussion · 05/05/2008 (8:19 am) · 7 replies

I am working on a simplified game where I need to have the player pickup items in the game. There are three different kinds of items and once they get all three items the game will end. Currently when the player picks up any one of the items the score changes but then it calls victory. My counter goes up one and then calls victory even though I didn't find the other two items. The command getCount is unknown in the console. I am not sure how to explain to the script what getCount is. Please let me know what I need to do to fix this. Thanks for any help!

When I grabbed pot3 the last time the console shows:

game/server/pot3.cs (69): Unknown command getCount.
Object pot3(24) pot3 -> ItemDate -> ShapeBaseData -> GameBaseData -> SimDataBlock -> SimObject
Mapping string: SetScoreCounter to index: 12
Mapping string: ShowVictory to index: 13


Here is my script for pot3

Line 14 datablock ItemData( pot3 )
Line 15 {

Line 18 category = "pot3";

Line 22 shapeFile = "~/data/pot3/pot3.dts";
Line 23 shapeFile = "~/data/shapes/pot3/pot3.dts";

Line 25 };


Line 33 function ItemData::create( %data )
Line 34 {
Line 35 echo( "ItemData::create for pot3 called --------------------------" );

Line 37 %obj = new Item()
Line 38 {
Line 39 dataBlock = %data;
Line 40 rotate = true; // All Pots will rotate.
Line 41 static = true; // Pots should stay put so they don't slide away.

Line 43 };

Line 45 return %obj;
Line 46 }


Line 53 function pot3::onCollision( %this, %obj, %col )

Line 54 {

Line 55 echo( "pot3::onCollision called ----------------------------------" );



Line 59 }

Line 60 function pot3::onCollision(%this, %obj, %col)

Line 61{

Line 62 if(%col.getClassName() $= "Player")

Line 63 {

Line 64 %client = %col.client;

Line 65 %client.score++;

Line 66 commandToClient(%client, 'SetScoreCounter', %client.score);


Line 68 %obj.delete();

Line 69 %pot1Count = pot1.getCount();

Line 70 %pot2Count = pot2.getCount();
Line 71 %pot3Count = pot3.getCount();
Line 72 if((%pot1Count > 0)(%pot2Count > 0)(%pot3Count > 0))
Line 73 return;

Line 75 commandToClient(%client, 'ShowVictory', %client.score);
Line 76 }
Line 77 }

#1
05/05/2008 (9:31 am)
I simplified even more of this and I just can't figure out what getCount is or how to set it. Even when I set the item up as a static object it still does not know what getCount is. Here is the latest. If I only have 1 type of item in the game as soon as I pickup the first item it ends the game giving me the congratulations message. I still have other items left so the items left is not zero.

It doesn't get much simpler than this but I still don't know what it means by getCount

datablock StaticShapeData( pot1 )
{
category = "Items";
shapeFile = "~/data/shapes/pot1/pot1.dts";
};

function pot1::onCollision(%this, %obj, %col)
{
if(%col.getClassName() $= "Player")
{
%client = %col.client;
%client.score++;
commandToClient(%client, 'SetScoreCounter', %client.score);

%obj.delete();
%potCount = pot.getCount();
if(%potCount > 0)
return;
// otherwise display victory screen
commandToClient(%client, 'ShowVictory', %client.score);
}
}
#2
05/05/2008 (9:53 am)
I looked at the log and found this.

No error when it loads the script:

Loading compiled script game/server/pot1.cs.



An error here once I run the game:

game/server/pot1.cs (16): Unknown command getCount.
Object pot1(22) pot1 -> StaticShapeData -> ShapeBaseData -> GameBaseData -> SimDataBlock -> SimObject
Mapping string: SetScoreCounter to index: 12
Mapping string: ShowVictory to index: 13
#3
05/05/2008 (10:01 am)
The error says that the function/method 'getCount' isn't defined for the object you are calling it on. Don't see a definition for the method in your source dumps.
#4
05/05/2008 (10:13 am)
Try:

%potCount = %this.getCount();

or

%potCount = %obj.getCount();
#5
05/05/2008 (10:22 am)
Rene,
How do I define for the method? I am new to this so I don't understand what function/method.


mb,

I tried what you gave me and I got the same error on the first script:

game/server/pot1.cs (16): Unknown command getCount.
Object pot1(22) pot1 -> StaticShapeData -> ShapeBaseData -> GameBaseData -> SimDataBlock -> SimObject
Mapping string: SetScoreCounter to index: 12
Mapping string: ShowVictory to index: 13


On the second script I got:
game/server/pot1.cs (16): Unable to find object: '1567' attempting to call function 'getCount'
Mapping string: SetScoreCounter to index: 12
Mapping string: ShowVictory to index: 13
#6
05/05/2008 (10:40 am)
@Greg

I would make a variable that tracks the pot. The easiest way would be to make a global variable on the server in game.cs in the function onServerCreated().

$potsRemaining = 20; // change 20 to whatever.

Then decrement every time you collide..

function pot1::onCollision(%this, %obj, %col)
{
if(%col.getClassName() $= "Player")
{
%client = %col.client;
%client.score++;
$potsRemaining--;

That way $potsRemaining always contains the right number and it's easy to access.
#7
05/05/2008 (11:19 am)
Thanks for all your help!

I found out what I was doing wrong. Both of you pointed me in the right direction. Guess it is what I get for jumping in and trying it. I needed to make a simgroup called pots. Then drag my static pots into that simgroup.