Trying to damage my player in script... questions...
by Ted Southard · in Torque Game Engine · 03/17/2004 (10:18 am) · 4 replies
Okay, so I'm a little new at scripting, having been at it for only a week or two...
What I'm looking at doing is clicking on a GUI button and having that damage my player(this is for testing combat routines, I figure it's the simplest way for the moment).
What I have so far is the GUI setup, a bitmap button with a command mapped to "commandToServer('Hit');". That works simple enough.
In server/scripts/ I have a script with the function below:
function serverCmdHit()
{
%this.player.hitSelf();
}
Which is a call to a function I placed in server/scripts/player.cs:
function Player::hitSelf(%this)
{
%client = %this.client;
%client.player.damage(0, 0, 50, "Impact");
}
Now, when I run the demo, I get the message "Unable to find object: ' ' attempting to call function 'hitSelf'".
So, the question is, besides all of the other things I'm probably doing wrong in the above script: How do I get a hold of a valid %player in order to call these functions? I know % designates a local variable, and I haven't found a global one that corresponds(which makes sense), but I'm not sure where to put the functions where they can use that %player variable and still be called from the gui(or from a generic function that can be called from the gui, even). Any thoughts or suggestions? Thanks in advance!
What I'm looking at doing is clicking on a GUI button and having that damage my player(this is for testing combat routines, I figure it's the simplest way for the moment).
What I have so far is the GUI setup, a bitmap button with a command mapped to "commandToServer('Hit');". That works simple enough.
In server/scripts/ I have a script with the function below:
function serverCmdHit()
{
%this.player.hitSelf();
}
Which is a call to a function I placed in server/scripts/player.cs:
function Player::hitSelf(%this)
{
%client = %this.client;
%client.player.damage(0, 0, 50, "Impact");
}
Now, when I run the demo, I get the message "Unable to find object: ' ' attempting to call function 'hitSelf'".
So, the question is, besides all of the other things I'm probably doing wrong in the above script: How do I get a hold of a valid %player in order to call these functions? I know % designates a local variable, and I haven't found a global one that corresponds(which makes sense), but I'm not sure where to put the functions where they can use that %player variable and still be called from the gui(or from a generic function that can be called from the gui, even). Any thoughts or suggestions? Thanks in advance!
About the author
Started with indie games over a decade ago, and now creates tools and tech for games. Currently working as a contractor for startups and game studios.
#2
I can't pass a %client to commandToServer('Hit(%client)'); because I then get "Unknown Command" errors for that.
So the question is where do I pull %client from if the command is being called from the gui? Do I need to place a command like this within a specific namespace to get to %client?
03/17/2004 (11:27 am)
Tried it, and I still get that error "Unable to find object: ' ' attempting to call function Damage"I can't pass a %client to commandToServer('Hit(%client)'); because I then get "Unknown Command" errors for that.
So the question is where do I pull %client from if the command is being called from the gui? Do I need to place a command like this within a specific namespace to get to %client?
#3
03/17/2004 (11:31 am)
Or, another question might be able to get me around this: How do I access a namespace to call a function from the gui, ie Armor::damage?
#4
command = "commandToServer('Hit');";
And server-side, the following:
function serverCmdHit(%client)
{
%client.player.applyDamage(50);
}
And that seemed to work. Even though applyDamage is more direct access, and the scripts I've looked at say to go through collision methods to do damage, since I'm using dice rolls instead, it's far simpler and does exactly what I need it to. Thanks for your help too, Ian! Took a bit to figure out the whole %client thing.. :)
03/17/2004 (1:15 pm)
Okay, I got it. What I did was put the following client-side(within the bitmap button):command = "commandToServer('Hit');";
And server-side, the following:
function serverCmdHit(%client)
{
%client.player.applyDamage(50);
}
And that seemed to work. Even though applyDamage is more direct access, and the scripts I've looked at say to go through collision methods to do damage, since I'm using dice rolls instead, it's far simpler and does exactly what I need it to. Thanks for your help too, Ian! Took a bit to figure out the whole %client thing.. :)
Associate Ian Omroth Hardingham
Mode 7 Games
{
%this.player.damage(0,0,50,"impact");
}
Should do it. Your first problem is missing out the %client argument in you serverCmdHit function.
Ian