Game Development Community

Problem calling a level class function

by Brian Kelly · in Torque Game Builder · 08/19/2006 (7:06 am) · 4 replies

THE SCENARIO:

I created a level in the editor and set its Scene Graph Scripting Class to "zombieLevel". Then I made a script file called "zombielevel.cs" in my scripts directory. In there I have the following functions:

function ZombieLevel::setZombieTarget(%this, %target) {
	$zombieTarget = %target;	
}

function ZombieLevel::getZombieTarget(%this) {
	return $zombieTarget;
}

Then in my game.cs I have the following:

function startGame(%level) {
	exec("./zombielevel.cs");
	exec("./player.cs");

Finally, my player.cs file has the following:

function Player::onLevelLoaded(%this, %scenegraph) {
	$Player = %this;

	moveMap.bindCmd(keyboard, "up", "PlayerUp();", "PlayerUpStop();");
	moveMap.bindCmd(keyboard, "down", "PlayerDown();", "PlayerDownStop();");
	moveMap.bindCmd(keyboard, "left", "PlayerLeft();", "PlayerLeftStop();");
	moveMap.bindCmd(keyboard, "right", "PlayerRight();", "PlayerRightStop();");
	moveMap.bindCmd(keyboard, "space", "PlayerBoost();", "PlayerBoostStop();");

	%scenegraph.setZombieTarget(%this);
}

THE PROBLEM:

When I run the game I get the following error:

Executing MyZombieGame/gameScripts/game.cs.
Setting screen mode to 800x600x32 (w)...
Executing MyZombieGame/gameScripts/zombielevel.cs.
Executing MyZombieGame/gameScripts/player.cs.
Executing MyZombieGame/Data/levels/four_corners.t2d.
MyZombieGame/gameScripts/player.cs (12): Unknown command setZombieTarget.
  Object (3967) zombieLevel -> t2dSceneGraph -> SimSet -> SimObject

With the last line being the problem. I definitely have setZombieTarget as a function in my level class, so I'm not sure why my player class can't see it. I followed the Whack-a-Mole tutorial which has similar functionality for keeping track of how many moles were whacked (moleLevel::incWhackedCount)

Anybody have any insight?

#1
08/19/2006 (12:17 pm)
It appears as though you have a case sensitivity issue:

Object (3967) zombieLevel -> t2dSceneGraph -> SimSet -> SimObject

In this, it's refered to as zombieLevel but in your zombielevel.cs you refer to it as ZombieLevel

Try changing the case in your zombielevel.cs to reflect a lower-case 'z' and see if that's the issue.
#2
08/19/2006 (12:34 pm)
The TorqueScript Overview states:
"Case-insensitive - TorqueScript ignores case when interpreting variable and
function names."

But I went and made the name consistent everywhere (the Class name, the file name, the reference in the exec line and the level scripting reference) and it still gives me the same error.
#3
08/19/2006 (12:38 pm)
Ha! Your post led me to the problem!

In the level's Scene Graph Scripting:Class box I had typed "zombieLevel" but apparently I also hit Control-S while the focus was still on that text box and it ended up putting a control character at the end of the value. Once I removed that, my script executed as expected!
#4
08/19/2006 (1:24 pm)
Brian,

ahh -- nice. glad I ccould point in the right direction :)