Cannot Find Object "Player"???
by David Ravel · in Torque Game Builder · 02/27/2009 (3:55 pm) · 6 replies
I've set up my potion to call this function, PotionState, but it tells me it cannot find the object "Player", which is very bizarre. Here is the potion's function followed by my revised version of the PotionState function. You might be wondering why I use a switch for the potion but I'm doing it because my potion system will actually be more complex once I can get the basic version to run.
function potionA::onEnter( %this )
{
switch($potionState)
{
case 0:
$potionState++;
echo($potionState);
Player.PotionState();
case 1:
$potionState++;
echo($potionState);
Player.PotionState();
case 2:
$potionState++;
echo($potionState);
Player.PotionState();
}
}
function Player::PotionState(%this)
{
switch($potionState)
{
case 0:
Player.MaxMoveSpeed = 16;
echo("case 0");
case 1:
Player.MaxMoveSpeed = 12;
echo("case 1");
case 2:
Player.MaxMoveSpeed = 8;
echo("case 2");
case 3:
Player.MaxMoveSpeed = 4;
echo("case 3");
case -1:
Player.MaxMoveSpeed = 12;
echo("case -1");
case -2:
Player.MaxMoveSpeed = 32;
echo("case -2");
case -3:
Player.MaxMoveSpeed = 32;
echo("case -3");
}
}
Thanks a lot,
Dave
function potionA::onEnter( %this )
{
switch($potionState)
{
case 0:
$potionState++;
echo($potionState);
Player.PotionState();
case 1:
$potionState++;
echo($potionState);
Player.PotionState();
case 2:
$potionState++;
echo($potionState);
Player.PotionState();
}
}
function Player::PotionState(%this)
{
switch($potionState)
{
case 0:
Player.MaxMoveSpeed = 16;
echo("case 0");
case 1:
Player.MaxMoveSpeed = 12;
echo("case 1");
case 2:
Player.MaxMoveSpeed = 8;
echo("case 2");
case 3:
Player.MaxMoveSpeed = 4;
echo("case 3");
case -1:
Player.MaxMoveSpeed = 12;
echo("case -1");
case -2:
Player.MaxMoveSpeed = 32;
echo("case -2");
case -3:
Player.MaxMoveSpeed = 32;
echo("case -3");
}
}
Thanks a lot,
Dave
#2
Yes I have and it is in game and functioning in all other respects. I'm using the adventure kit for a lot of the script and this is appended on the end of their Player script.
02/27/2009 (10:55 pm)
As in an instance of the class "Player"?Yes I have and it is in game and functioning in all other respects. I'm using the adventure kit for a lot of the script and this is appended on the end of their Player script.
#3
Is it an instance of a Player class or an instance of a class that you've named Player?
For example, are you doing this?
new Player();
or
new Player(Bob);
or
new SomeOtherClass(Player);
02/28/2009 (6:44 pm)
I don't have the adventure kit, so I don't know the specifics of what they do, but...Is it an instance of a Player class or an instance of a class that you've named Player?
For example, are you doing this?
new Player();
or
new Player(Bob);
or
new SomeOtherClass(Player);
#4
function playerCreate( %sg, %visible )
{
if ( %visible $= "" )
%visible = true;
%player = new t2dAnimatedSprite()
{
config = PlayerConfig;
scenegraph = %sg;
visible = %visible;
// Make sure the player is always created way
// offscreen so that it doesn't inadvertently
// appear within a critical trigger.
position = "-10000 -10000";
};
// Enable tick updates.
%player.enableUpdateCallback();
return %player;
}
Sorry, I'm really new. This might not even be the right function but I couldn't find anything else that looked like it initialized the player.
02/28/2009 (8:29 pm)
I think it might be the third option. This is the function that creates the player.function playerCreate( %sg, %visible )
{
if ( %visible $= "" )
%visible = true;
%player = new t2dAnimatedSprite()
{
config = PlayerConfig;
scenegraph = %sg;
visible = %visible;
// Make sure the player is always created way
// offscreen so that it doesn't inadvertently
// appear within a critical trigger.
position = "-10000 -10000";
};
// Enable tick updates.
%player.enableUpdateCallback();
return %player;
}
Sorry, I'm really new. This might not even be the right function but I couldn't find anything else that looked like it initialized the player.
#5
As long as the function is assigned to something, you can change your code to look similar the following, but don't make the change until you read more below:
The form "function Player::functionName( %this )" is for when you have a class or namespace called Player.
One way to make your animated sprite a "Player" class is to do the following:
In this case, your code would need the following modifications:
To learn more about classes and namespaces, visit tdn.garagegames.com.
(Note: All code was off-the-cuff. If there are compile errors, just let me know and I'll see what I may have done wrong.)
02/28/2009 (8:53 pm)
This looks promising. I'm sure that somewhere this function is called, hopefully something like:$PLAYER = playerCreate( sceneGraph, true );
As long as the function is assigned to something, you can change your code to look similar the following, but don't make the change until you read more below:
function potionA::onEnter( %this )
{
switch($potionState)
{
case 0:
$potionState++;
echo($potionState);
potionState( $PLAYER );
}
}
function potionState(%aPlayer)
{
switch($potionState)
{
case 0:
%aPlayer.MaxMoveSpeed = 16;
echo("case 0");
}
}The form "function Player::functionName( %this )" is for when you have a class or namespace called Player.
One way to make your animated sprite a "Player" class is to do the following:
%player = new t2dAnimatedSprite()
{
class = "Player"; // This defines the class
config = PlayerConfig;
scenegraph = %sg;
visible = %visible;
// Make sure the player is always created way
// offscreen so that it doesn't inadvertently
// appear within a critical trigger.
position = "-10000 -10000";
};In this case, your code would need the following modifications:
function potionA::onEnter( %this )
{
switch($potionState)
{
case 0:
$potionState++;
echo($potionState);
$PLAYER.potionState();
}
}
function Player::potionState( %this )
{
switch($potionState)
{
case 0:
%this.MaxMoveSpeed = 16;
echo("case 0");
}
}To learn more about classes and namespaces, visit tdn.garagegames.com.
(Note: All code was off-the-cuff. If there are compile errors, just let me know and I'll see what I may have done wrong.)
#6
EDIT: The script now works perfectly, thanks a lot!
03/01/2009 (10:18 am)
I think your latter suggestion is what makes sense because the player class is defined in the playerconfig datablock. I'll try some of that stuff out and see if it works.datablock t2dSceneObjectDatablock( PlayerConfig )
{
class = "Player";
superclass = "";
size = "16.113 16.113";
layer = 2;
sortPoint = "0 0.3";
animationName = orc_idle_south_anim;EDIT: The script now works perfectly, thanks a lot!
Associate William Lee Sims
Machine Code Games
Have you created an object with the namespace "Player"?