Developing a Battle System (discussion)
by Infinitum3D · in Torque Game Engine · 05/06/2009 (9:45 am) · 67 replies
I have TGE 1.5.2
The way I see it, there are three types of battles;
1. melee
2. ranged
3. magic
Torque has a basic 'ranged' battle system in effect.
I'm looking at player.cs and crossbow.cs first.
player.cs has datablock PlayerData(PlayerBody)
with the definition "maxDamage = 100;" which is commonly referred to as 'hit points'.
further down;
function Armor::onImpact applies damage %obj.damage()
and function Armor::damage applies damage
%obj.applyDamage(%damage);
and function Armor::onDamage does 3 things:
1.checks to see if player is dead
2.'flashes' the screen to show damage being done
3. plays an audio (pain) file
There are also the onEnterLiquid damage switch for Lava and finally the function Player::kill which looks like it assigns 10000 points damage to the player.
Crossbow.cs uses datablock ProjectileData(CrossbowProjectile)
which has the definitions
directDamage=20;
radiusDamage=20;
and further down
function CrossbowProjectile::onCollision()
which applies damage to ShapeBaseObjectTypes
So, what is my question?
Obviously this all applies to a 'ranged' battle system.
Would anyone care to comment on how they've adapted this to fit their game?
Are modifiers added through script, or are engine changes used? For example, if I wanted a more powerful (or less powerful) crossbow projectile, I could simple increase (or decrease) tthe directDamage variable.
But what I'm looking for is a discussion on various ways to modify this inherent battle system in TGE.
I know a 'melee' system resource exists (I've already added it), but for now, maybe we can just discuss 'ranged' modifications?
Any comments?
Tony
The way I see it, there are three types of battles;
1. melee
2. ranged
3. magic
Torque has a basic 'ranged' battle system in effect.
I'm looking at player.cs and crossbow.cs first.
player.cs has datablock PlayerData(PlayerBody)
with the definition "maxDamage = 100;" which is commonly referred to as 'hit points'.
further down;
function Armor::onImpact applies damage %obj.damage()
and function Armor::damage applies damage
%obj.applyDamage(%damage);
and function Armor::onDamage does 3 things:
1.checks to see if player is dead
2.'flashes' the screen to show damage being done
3. plays an audio (pain) file
There are also the onEnterLiquid damage switch for Lava and finally the function Player::kill which looks like it assigns 10000 points damage to the player.
Crossbow.cs uses datablock ProjectileData(CrossbowProjectile)
which has the definitions
directDamage=20;
radiusDamage=20;
and further down
function CrossbowProjectile::onCollision()
which applies damage to ShapeBaseObjectTypes
So, what is my question?
Obviously this all applies to a 'ranged' battle system.
Would anyone care to comment on how they've adapted this to fit their game?
Are modifiers added through script, or are engine changes used? For example, if I wanted a more powerful (or less powerful) crossbow projectile, I could simple increase (or decrease) tthe directDamage variable.
But what I'm looking for is a discussion on various ways to modify this inherent battle system in TGE.
I know a 'melee' system resource exists (I've already added it), but for now, maybe we can just discuss 'ranged' modifications?
Any comments?
Tony
#42
Recommended but not necessary. But it is better to do that because this way you can create different Debris, Particle Effects and Explosions for each type of projectile.
05/08/2009 (10:45 am)
Quote:
First, each type needs a datablock, so that we can place them in our world.
Recommended but not necessary. But it is better to do that because this way you can create different Debris, Particle Effects and Explosions for each type of projectile.
#43
When you do a new ObjectType(){
dynamicField1 = something;
dynamicField2 = somethingElse;
};
See those things? They were dynamic fields. They are the personal property of the new object created.
05/08/2009 (1:22 pm)
Quote:This projectile CreateProjectile(70,20,10); would apply 70 damage to AI_Soldier, 20 to AI_Alien and 10 to AI_Mummy, correct?Assuming you script the correct logic when the projectile hits - check whether you hit a mummy, an alien or a soldier and then use the appropriate dynamic field to calculate how much damage is done.
Quote:which defines all the specific parameters for that specific bolt
Quote:This doesn't seem to use Dynamic Fields, though.You just pointed out where dynamic fields are used ;)
When you do a new ObjectType(){
dynamicField1 = something;
dynamicField2 = somethingElse;
};
See those things? They were dynamic fields. They are the personal property of the new object created.
#44
And they are permanent to that specific object as long as it exists, but since they are dynamic they can be changed through other scripts?
05/08/2009 (1:34 pm)
Quote:They are the personal property of the new object created
And they are permanent to that specific object as long as it exists, but since they are dynamic they can be changed through other scripts?
#45
Yes
Yes
You can also define personal methods for your objects.
Example: You have all the created projectiles in a SimGroup called ProjectileGroup...
To add a projectile to this group simply type this:
05/08/2009 (1:59 pm)
Quote:
And they are permanent to that specific object as long as it exists,...
Yes
Quote:
... but since they are dynamic they can be changed through other scripts?
Yes
You can also define personal methods for your objects.
Example: You have all the created projectiles in a SimGroup called ProjectileGroup...
%count = ProjectileGroup.getCount();
for (%i=0; %i<%count; %i++)
{
%proj = ProjectileGroup.getObject(%i);
echo(%proj.getProjectileDamage()); // this is your personal method
}To add a projectile to this group simply type this:
%projectile = CreateProjectile("SniperProjectile");
if (!isObject(ProjectileGroup)) // check if SimGroup "ProjectileGroup" exists
{
new SimGroup(ProjectileGroup); // if not... create the group
}
ProjectileGroup.Add(%projectile); // add the projectile to the group;
#46
So Thomas's method would be defined something like this:
05/08/2009 (11:46 pm)
Quote:You can also define personal methods for your objects.
echo(%proj.getProjectileDamage()); // this is your personal methodThis isn't a method defined only for that object, though - it's a method that is called on the specific object. But you can call the same method on any other object of the right type.
So Thomas's method would be defined something like this:
function Projectile::getProjectileDamage(%obj)
{
return %obj.directDamage; //Or whatever
}
#47
The difference between a method for a object-class and a datablock-class is that the first parameter is always the datablock itself. The second parameter is the current object.
05/09/2009 (1:26 am)
If you want to define your own method in a datablock: function ProjectileData::getSomething(%this, %obj)
{
return %obj.aValue; // return a value from the object (not the datablock)
}The difference between a method for a object-class and a datablock-class is that the first parameter is always the datablock itself. The second parameter is the current object.
#48
This tag-teaming thing must be confusing ;P.
05/09/2009 (3:06 am)
The difference between these two methods is that you call mine on a Projectile object, and Thomas's on a ProjectileData datablock. You could also define Thomas's method like this:function CrossbowProjectile::myFunction(%this,%obj)
{
//...
}This function can only be used on the ProjectileData datablock named CrossbowProjectile.This tag-teaming thing must be confusing ;P.
#49
Define method.
I know what a function is and I can use them (although I'm still a little fuzzy on using them). A function is a piece of script (or code) that gets called by an event (a keypress, or an occurrence like a collision onCollision, or taking damage onDamage, or entering a trigger onEnterTrigger, etc...)
Right?
So what does the term method mean. Is there a specific computerProgrammer definition, or does it just mean, 'a way to do something'?
Why would you call a method on a datablock (since datablocks are hardcoded and static)?
Thanks!
Tony
ps. this is a HUGE benefit for a non-programmer, so the moderator should make this a sticky in a gettingStarted forum! :)
05/15/2009 (2:59 pm)
OK, hang on.Define method.
I know what a function is and I can use them (although I'm still a little fuzzy on using them). A function is a piece of script (or code) that gets called by an event (a keypress, or an occurrence like a collision onCollision, or taking damage onDamage, or entering a trigger onEnterTrigger, etc...)
Right?
So what does the term method mean. Is there a specific computerProgrammer definition, or does it just mean, 'a way to do something'?
Why would you call a method on a datablock (since datablocks are hardcoded and static)?
Thanks!
Tony
ps. this is a HUGE benefit for a non-programmer, so the moderator should make this a sticky in a gettingStarted forum! :)
#50
Example:
setScreenMode(...) ist simply a function.
But setVelocity is a method because it is a "function" of a object.
The terms property (incl. dynamic fields) and method are equal to variable and function.
Property and Method are terms of OOP ( Object Oriented Programming ).
I learned a lot from this book. Highly recommended !!!!!!!
www.garagegames.com/products/gameprogrammersguide
There is everything you want to know about TorqueScript.
05/16/2009 (12:06 am)
A method is nothing more than a function of a object. Example:
setScreenMode(...) ist simply a function.
But setVelocity is a method because it is a "function" of a object.
The terms property (incl. dynamic fields) and method are equal to variable and function.
Property and Method are terms of OOP ( Object Oriented Programming ).
I learned a lot from this book. Highly recommended !!!!!!!
www.garagegames.com/products/gameprogrammersguide
There is everything you want to know about TorqueScript.
#51
Datablocks are objects to optimize multiplayer games (the used traffic). Datablocks are only sent once to the clients. After that... only the IDs of the Datablocks are sent because IDs produce less traffic than the complete datablock.
The same with strings and tagged strings.
Tagged strings, like datablocks, are also sent once. After that, only the ID of the string is sent.
05/16/2009 (12:29 am)
Quote:
Why would you call a method on a datablock (since datablocks are hardcoded and static)?
Datablocks are objects to optimize multiplayer games (the used traffic). Datablocks are only sent once to the clients. After that... only the IDs of the Datablocks are sent because IDs produce less traffic than the complete datablock.
The same with strings and tagged strings.
%text = "I am a string"; %text = 'I am a tagged string';
Tagged strings, like datablocks, are also sent once. After that, only the ID of the string is sent.
#52
Re-reading this thread, way back in post #3, Matt says something like "When you have created an object, you can modify the values that it inhereted from the datablock".
That's done using a dynamic field then, right?
And a method is a function of an object...
Meaning, some action that the object can perform?
So the method (being a function) can be called from elsewhere in the script? Why call it a method and not just use the term function? It looks like a method is more specific (function of an object).
All functions don't act on objects then, right? Only methods act on object?
I wrote a logic program back in the 80's in BASIC on a Commodore128 that said something like:
All kittens are cats
All cats are not kittens
Is this the same concept then, between methods and functions?
All methods are functions
All functions are not methods
Every time I re-read this thread I understand it better.
Thanks again! And thanks for the book link. I'll have to check it out.
I'll ask about ID's in my next post :) I know serverID and clientID are not the same number, and there's something about Ghosting, but I don't even know where to begin with that.
So a CLASS is like a box that holds all the data (both VARIABLES and FUNCTIONS) for a single object type. the VARIABLES (of a class) are called ARGUMENTS or MEMBERS, and the FUNCTIONS (of that object class) are called METHODS.
I think I'm getting there.
Tony
05/16/2009 (4:35 pm)
OK, I'm learning!Re-reading this thread, way back in post #3, Matt says something like "When you have created an object, you can modify the values that it inhereted from the datablock".
That's done using a dynamic field then, right?
And a method is a function of an object...
Meaning, some action that the object can perform?
So the method (being a function) can be called from elsewhere in the script? Why call it a method and not just use the term function? It looks like a method is more specific (function of an object).
All functions don't act on objects then, right? Only methods act on object?
I wrote a logic program back in the 80's in BASIC on a Commodore128 that said something like:
All kittens are cats
All cats are not kittens
Is this the same concept then, between methods and functions?
All methods are functions
All functions are not methods
Every time I re-read this thread I understand it better.
Thanks again! And thanks for the book link. I'll have to check it out.
I'll ask about ID's in my next post :) I know serverID and clientID are not the same number, and there's something about Ghosting, but I don't even know where to begin with that.
So a CLASS is like a box that holds all the data (both VARIABLES and FUNCTIONS) for a single object type. the VARIABLES (of a class) are called ARGUMENTS or MEMBERS, and the FUNCTIONS (of that object class) are called METHODS.
I think I'm getting there.
Tony
#53
Copy the code and start with groupTest(); in your console.
05/16/2009 (11:22 pm)
Here is a simple example// expand namespace "SimGroup" with your own method
// %this is the object itself (the instance)
function SimGroup::listAllObjects(%this)
{
echo("number of objects in group " @ %this.getName() @ ": " @ %this.getCount());
%count = %this.getCount();
for (%i=0; %i<%count; %i++)
{
%obj = %this.getObject(%i);
echo(%this.getName() @ ": " @ %obj.getName() @ " myRandomValue: " @ %obj.myRandomValue);
}
}
// this is a function (not a method)
function groupTest()
{
%groupOne = new SimGroup(); // create two SimGroups
%groupTwo = new SimGroup();
%groupOne.setName("<< The first Group >>"); // set the Names
%groupTwo.setName("<< The second Group >>");
// create 10 ScriptObjects with a dynamic field called myRandomValue
// if %i is even... add the ScriptObject to the first Group otherwise to the second Group
for (%i=0; %i<10; %i++)
{
%tempObject = new ScriptObject();
%tempObject.setName("I am Object #" @ %i);
%tempObject.myRandomValue = getRandom(1, 100); // this is a dynamic field
if (%i % 2 == 0)
{
%groupOne.add(%tempObject);
}
else
{
%groupTwo.add(%tempObject);
}
}
// now call your own method implemented in the namespace "SimGroup"
%groupOne.listAllObjects();
echo("");
%groupTwo.listAllObjects();
}Copy the code and start with groupTest(); in your console.
#54
Correct.
Correct.
Yes, if you know the ID of the object.
It is a specific type of naming in OOP (Object Oriented Programming).
Methods are like a private life of objects.
Ah, the ID's, Ghosting, Scoping and ControlObjects. A very interesting topic.
You are right, ID's on the Server and ID's on the Clients are not identical. With one exception: Datablocks. ID's of datablocks are identical on the server side and the client side.
Ghosting is easy to understand. All objects are ghosted to all clients because the handling of the real objects is done by the server (ONLY by the server). The task of the server is to manage the gameplay. And the result of these calculations is ghosted to all clients (position and rotation of the player(s), bot(s) and so on).
05/17/2009 (12:05 am)
Quote:
So a CLASS is like a box that holds all the data (both VARIABLES and FUNCTIONS) for a single object type. the VARIABLES (of a class) are called ARGUMENTS or MEMBERS, and the FUNCTIONS (of that object class) are called METHODS.
Correct.
Quote:
And a method is a function of an object...
Meaning, some action that the object can perform?
Correct.
Quote:
So the method (being a function) can be called from elsewhere in the script?
Yes, if you know the ID of the object.
Quote:
Why call it a method and not just use the term function? It looks like a method is more specific (function of an object).
It is a specific type of naming in OOP (Object Oriented Programming).
Quote:
All functions don't act on objects then, right? Only methods act on object?
Methods are like a private life of objects.
Quote:
I'll ask about ID's in my next post :) I know serverID and clientID are not the same number, and there's something about Ghosting, but I don't even know where to begin with that.
Ah, the ID's, Ghosting, Scoping and ControlObjects. A very interesting topic.
You are right, ID's on the Server and ID's on the Clients are not identical. With one exception: Datablocks. ID's of datablocks are identical on the server side and the client side.
Ghosting is easy to understand. All objects are ghosted to all clients because the handling of the real objects is done by the server (ONLY by the server). The task of the server is to manage the gameplay. And the result of these calculations is ghosted to all clients (position and rotation of the player(s), bot(s) and so on).
#55
The first argument passed by a method from a object is always the ID of the object itself.
If you use a method from a datablock... two arguments are passed to the method. The first argument is the ID of the datablock and the second argument is the ID of the corresponding object.
Example 1:
Example 2:
Don't care about the names %this and %obj. Instead you can use other names for your variables... if you want.
For example:
05/17/2009 (12:28 am)
One important thing i forgot to say: The first argument passed by a method from a object is always the ID of the object itself.
If you use a method from a datablock... two arguments are passed to the method. The first argument is the ID of the datablock and the second argument is the ID of the corresponding object.
Example 1:
function SimGroup::listAllObjects(%this)
{
// %this is the ID of the object
/// ...
}Example 2:
function DBProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
// DBProjectile is a datablock
// %this is the ID of the datablock
// %obj is the ID of your projectile
// ...
}Don't care about the names %this and %obj. Instead you can use other names for your variables... if you want.
For example:
function DBProjectile::onCollision(%x,%y,%col,%fade,%pos,%normal)
{
// DBProjectile is a datablock
// %x is the ID of the datablock
// %y is the ID of your projectile
// ...
}
#56
My next question; Other than the first (and with a datablock, the second) argument, do the rest have any significant order, or are the rest completely independent?
I do realize that variables can have ANY name you want, as long as you keep track of the name and use it consistently in the function. Even the first and second variables can be called %foo and %bar, as long as I am consistent throughout the function.
This has been an incredible help to me! Daniel can attest that I was getting %this and %obj mixed up in pretty much ALL of my other posts, and I think the reason was because I didn't comprehend that datablocks followed a different rule than objects (even Daniel tried to explain it to me, several times -sorry Daniel).
I think I finally understand.
And with Ghosting, a Ghost is basically a copy of the server data that is sent to the client. Its called a ghost because only the server data is real, the client is just a copy, right?
When a server sends out a ghost to the client, is the ghost ID of an object consistent across ALL clients, or just on a specific client? I would guess its consistent for ALL clients or the server would have to keep track of much more information. And the reason the ID is different between server and client is to prevent client "cheating" or something, right? A security measure?
Thanks!
Tony
05/17/2009 (7:16 am)
THAT'S what had me confused for the longest time. The First argument is ALWAYS the object ID, EXCEPT in the case of a DATABLOCK. In the case of a DATABLOCK, the FIRST argument is the DATABLOCK ID, and the SECOND argument is the OBJECT ID (which makes sense now).My next question; Other than the first (and with a datablock, the second) argument, do the rest have any significant order, or are the rest completely independent?
I do realize that variables can have ANY name you want, as long as you keep track of the name and use it consistently in the function. Even the first and second variables can be called %foo and %bar, as long as I am consistent throughout the function.
This has been an incredible help to me! Daniel can attest that I was getting %this and %obj mixed up in pretty much ALL of my other posts, and I think the reason was because I didn't comprehend that datablocks followed a different rule than objects (even Daniel tried to explain it to me, several times -sorry Daniel).
I think I finally understand.
And with Ghosting, a Ghost is basically a copy of the server data that is sent to the client. Its called a ghost because only the server data is real, the client is just a copy, right?
When a server sends out a ghost to the client, is the ghost ID of an object consistent across ALL clients, or just on a specific client? I would guess its consistent for ALL clients or the server would have to keep track of much more information. And the reason the ID is different between server and client is to prevent client "cheating" or something, right? A security measure?
Thanks!
Tony
#57
The onCollision-Callback as example:
The order has to be the same.
Correct.
Correct.
A client can not cheat because the handling of the gameplay is done by the server. The client is sending only a request to the server... for example... to move the player a little bit forward. Now the server moves the player forward and all clients will be informed ("ghosted") about the new position of this player.
I dont know. But i guess it is more or less insignificant. To start and stop ghosting the gameconnection-Object has two methods.
%clientConn.activateGhosting();
%clientConn.resetGhosting();
05/17/2009 (8:08 am)
Quote:
My next question; Other than the first (and with a datablock, the second) argument, do the rest have any significant order, or are the rest completely independent?
The onCollision-Callback as example:
DBProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
// DBProjectile is a datablock
// %this is the ID of the datablock
// %obj is the ID of your projectile
// ...
}The order has to be the same.
function SimGroup::doSomething(%this, %arg1, %arg2, %anotherArg)
{
// ...
}
%myGroup = new SimGroup();
%myGroup.doSomething(%x, %y, %z);
// inside the doSomething-Method:
// %this = the object itself
// %arg1 = %x;
// %arg2 = %y;
// %anotherArg = %z;Quote:
I do realize that variables can have ANY name you want, as long as you keep track of the name and use it consistently in the function. Even the first and second variables can be called %foo and %bar, as long as I am consistent throughout the function.
Correct.
Quote:
And with Ghosting, a Ghost is basically a copy of the server data that is sent to the client. Its called a ghost because only the server data is real, the client is just a copy, right?
Correct.
Quote:
When a server sends out a ghost to the client, is the ghost ID of an object consistent across ALL clients, or just on a specific client? I would guess its consistent for ALL clients or the server would have to keep track of much more information. And the reason the ID is different between server and client is to prevent client "cheating" or something, right? A security measure?
A client can not cheat because the handling of the gameplay is done by the server. The client is sending only a request to the server... for example... to move the player a little bit forward. Now the server moves the player forward and all clients will be informed ("ghosted") about the new position of this player.
Quote:
When a server sends out a ghost to the client, is the ghost ID of an object consistent across ALL clients, or just on a specific client?
I dont know. But i guess it is more or less insignificant. To start and stop ghosting the gameconnection-Object has two methods.
%clientConn.activateGhosting();
%clientConn.resetGhosting();
#58
To jump back a minute-
The order of each argument is specified by where the function is called. For example, onCollision callbacks (another word for function ;P) are called in the engine, with their arguments in a certain order. You have to use the same order - even if you rename all the arguments in the function header, the same values are being put into them.
Let's fall back on the old 'function machine' analogy. Think of each function as a machine that you put stuff into and might get stuff out of (whether or not anything comes out, *something* happens inside there). Imagine the machine as a big box with 'myFunction' written on it (that bit's not essential, but fun to imagine...). There are three pipes in the top.
Now, when the function is used, you put certain things in the three pipes, which are then processed inside the function. Each pipe stays the same, no matter what value you put into it, and no matter what labels you write on each pipe. For example:
That was a simple example - now try this one:
Now, if we called the function like this:
But if we called the function like this:
In short, nonsense in, nonsense out. Put your arguments in the right order ;P.
That was quite a lengthy answer to quite a short question. Well, hopefully it's useful.
I'll write some about the networking later, assuming Thomas doesn't cover it to the point where I have nothing left to add ;)
05/17/2009 (8:12 am)
No worries about all that - I remember clearly when I was having the exact same problem ;).To jump back a minute-
Quote:VARIABLES (of a class) are called ARGUMENTS or MEMBERSArguments are actually the variables in the definition of a function. So:
function myFunction(%foo,%bar)%foo and %bar are referred to as arguments. When you call the function:
myFunction(1,3);the values you pass in are put into the arguments of the function.
Quote:My next question; Other than the first (and with a datablock, the second) argument, do the rest have any significant order, or are the rest completely independent?[EDIT: Ninja'd... ah well. Hope this is still useful.]
The order of each argument is specified by where the function is called. For example, onCollision callbacks (another word for function ;P) are called in the engine, with their arguments in a certain order. You have to use the same order - even if you rename all the arguments in the function header, the same values are being put into them.
Let's fall back on the old 'function machine' analogy. Think of each function as a machine that you put stuff into and might get stuff out of (whether or not anything comes out, *something* happens inside there). Imagine the machine as a big box with 'myFunction' written on it (that bit's not essential, but fun to imagine...). There are three pipes in the top.
Now, when the function is used, you put certain things in the three pipes, which are then processed inside the function. Each pipe stays the same, no matter what value you put into it, and no matter what labels you write on each pipe. For example:
function subtract(%x,%y)
{
return %x - %y;
}In this function, %y is always subtracted from %x. So if we callecho(subtract(4,3));1 is echoed, whereas
echo(subtract(3,4));we get -1.
That was a simple example - now try this one:
function PlayerData::onSomeEventHappening(%this,%obj,%pos,%normal,%length)
{
if(%this.respondsToEvents)
{
%obj.setPosition(%pos);
%obj.faceTowards(%normal);
%obj.distance = %length;
}
}Npw, see that each argument of the function does something very specific. We check the datablock to make sure the event applies, then we set the object's position, call an imaginary function with a normal, and set the object's 'distance' member to equal the %length argument. I made all this stuff up, by the way, except setPosition is probably a real function.Now, if we called the function like this:
%aDataBlock.onSomeEventHappening(%aPlayer, "x y z", "i j k", 10);then we'd probably get results that made sense, assuming the arguments all make sense.
But if we called the function like this:
%aDataBlock.onSomeEventHappening(%aPlayer, "i j k", 10, "x y z");then some nonsense would happen. Because no matter what data we put in, the function will use it in that order. So in this case, tak the last argument - we've put a vector ("x y z") into the pipe that leads to the object's 'length' member. This makes no sense.
In short, nonsense in, nonsense out. Put your arguments in the right order ;P.
That was quite a lengthy answer to quite a short question. Well, hopefully it's useful.
I'll write some about the networking later, assuming Thomas doesn't cover it to the point where I have nothing left to add ;)
#59
So how do you know what order the arguments are supposed to be in, for each callback?
For instance, in your example:
is %pos, %normal, %length in a C++ order, or did you just pick the order?
Would this have worked as well?
Or does %pos ALWAYS come third for some reason? If I understand it correctly, only the %this and %obj are FIXED in their position. The rest can be ANY order, as long as they are consistent in their order within the specific function...
I hope I'm being clear in my question.
Thanks!
Tony
05/17/2009 (5:27 pm)
Quote:The order of each argument is specified by where the function is called. For example, onCollision callbacks (another word for function ;P) are called in the engine, with their arguments in a certain order.
So how do you know what order the arguments are supposed to be in, for each callback?
For instance, in your example:
function PlayerData::onSomeEventHappening(%this,%obj,%pos,%normal,%length)
{
if(%this.respondsToEvents)
{
%obj.setPosition(%pos);
%obj.faceTowards(%normal);
%obj.distance = %length;
}
}is %pos, %normal, %length in a C++ order, or did you just pick the order?
Would this have worked as well?
function PlayerData::onSomeEventHappening(%this,%obj,%normal,%length,%pos)
{
if(%this.respondsToEvents)
{
%obj.faceTowards(%normal);
%obj.distance = %length;
%obj.setPosition(%pos);
}
}Or does %pos ALWAYS come third for some reason? If I understand it correctly, only the %this and %obj are FIXED in their position. The rest can be ANY order, as long as they are consistent in their order within the specific function...
I hope I'm being clear in my question.
Thanks!
Tony
#60
Infinitum, take a minute and think about.
A few examples:
You can see, that you can use every name you want but the order is ALWAYS the same.
So the order of this callback is always:
1. ID of the Datablock
2. ID of the Object itself
3. Position
4. Rotation
5. Scale
But it is up to you to use any names for your local variables.
05/18/2009 (12:34 am)
Quote:
Or does %pos ALWAYS come third for some reason? If I understand it correctly, only the %this and %obj are FIXED in their position. The rest can be ANY order, as long as they are consistent in their order within the specific function...
Infinitum, take a minute and think about.
A few examples:
function ProjectileData::onSomeHappening(%this,%obj,%pos, %rotation, %scale)
{
// %this is the Daatablock
// %obj is the object itself
// %pos is the position
// %rotation is the rotation
// %scale is the scale
}
function ProjectileData::onSomeHappening(%this,%obj,%x, %y, %z)
{
// %this is the Daatablock
// %obj is the object itself
// %x is the position
// %y is the rotation
// %z is the scale
}
function ProjectileData::onSomeHappening(%a,%b,%c, %d, %e)
{
// %a is the Daatablock
// %b is the object itself
// %c is the position
// %d is the rotation
// %e is the scale
}
function ProjectileData::onSomeHappening(%this,%obj,%usa, %germany, %france)
{
// %this is the Daatablock
// %obj is the object itself
// %usa is the position
// %germany is the rotation
// %france is the scale
}
function ProjectileData::onSomeHappening(%pos,%obj,%this, %scale, %rotation)
{
// %pos is the Daatablock
// %obj is the object itself
// %this is the position
// %scale is the rotation
// %rotation is the scale
}You can see, that you can use every name you want but the order is ALWAYS the same.
So the order of this callback is always:
1. ID of the Datablock
2. ID of the Object itself
3. Position
4. Rotation
5. Scale
But it is up to you to use any names for your local variables.
Torque 3D Owner Thomas Bang
Perfect.
Wrong.
%skill, %experience, %foo, %bar, etc. should be the dynamic fields when you create a projectile.