Quick question (?) about script and the game loop
by Dean · in Torque Game Engine · 06/17/2007 (7:50 pm) · 6 replies
New here... I've learned how to create scripts and write functions in my game, but i'm used to coding and having a main game loop to make checks and decide when to run the functions I've written. I'm unsure of where to put the calls in my script to run the script functions i want to run in every loop. For example some scripts like this, that would normally go in the main loop of a game:
// just a general idea of the kind of scripts i'm talking about
if (testisplayerattacking(player))
if (testdidplayermakecontact(player,playertarget))
calculatedamage(player,playertarget);
// just a general idea of the kind of scripts i'm talking about
if (testisplayerattacking(player))
if (testdidplayermakecontact(player,playertarget))
calculatedamage(player,playertarget);
#2
When developing Torque games, you kind of have to break out of that mind set, especially when dealing with scripting.
In reference to your example, here's a script based solution:
Assuming you have a PlayerData(Armor) in script:
The collision will now happen automatically, and you aren't stuck in a game loop. This is a very, very loose example, but it demonstrates the difference between traditional C++/WinAPI/MFC looping vs a scripted game event.
I can get more specific and provide real, detailed functions, but I just wanted to present an example to get you started. Let me know if you have more questions
06/17/2007 (9:23 pm)
Coming from the same background of having a very controlled, C++ main loop, I can understand your confusion.When developing Torque games, you kind of have to break out of that mind set, especially when dealing with scripting.
In reference to your example, here's a script based solution:
Assuming you have a PlayerData(Armor) in script:
function Armor::onCollision(%this, %obj, %col)
{
if(%col.getClassName() $= "Projectile" || %col.getClassName() $= "MeleeWeapon")
%obj.damage(10); [b]// Hardcoded damage value[/b]
}
function Armor::damage(%this, %val)
{
[b]// Apply damage algorithm you decide (like armor vs raw damage)[/b]
}The collision will now happen automatically, and you aren't stuck in a game loop. This is a very, very loose example, but it demonstrates the difference between traditional C++/WinAPI/MFC looping vs a scripted game event.
I can get more specific and provide real, detailed functions, but I just wanted to present an example to get you started. Let me know if you have more questions
#3
So if there's some sort of player::onAnimationComplete(), i can simply verify that it was an attack animation and calculate my damage when the swing animation ends (if i make my animation end at the time of impact). from there I'm assuming I can use onDamage();
so, is there a way to test if the animation is complete that would work the way I'm describing?
06/17/2007 (10:46 pm)
Hmm well my game doesn't need to test for collisions. it always makes contact if the player swings (player can only swing if he's close enough to hit) like a classic rpg system. So if there's some sort of player::onAnimationComplete(), i can simply verify that it was an attack animation and calculate my damage when the swing animation ends (if i make my animation end at the time of impact). from there I'm assuming I can use onDamage();
so, is there a way to test if the animation is complete that would work the way I'm describing?
#4
... but it's not working. I currently have a punch animation (non cyclic) and i push j to execute the punch. he punches... but no echo. At least I'm getting closer to the answer (hopefully)
here's the line where it sends "animationDone"
I'm not sure why my animation doesn't "qualify". does the animation need some sort of requirement before it'll send ? It looks like it only does it if the player is in a certain animation. Does your animation have to return to the root position or something? In the code, i can manually send animation done by removing the if, and my script functions work.
06/17/2007 (11:15 pm)
I tried something from another thread, adding this to server/scripts/player.cs function Player::animationDone(%this,%obj)
{
// Inform the client
if (isObject(%obj.client.player))
{
echo("Player::animationDone");
}
}i also tried it with function Player::onEndSequence(%this,%obj,%slot)... but it's not working. I currently have a punch animation (non cyclic) and i push j to execute the punch. he punches... but no echo. At least I'm getting closer to the answer (hopefully)
here's the line where it sends "animationDone"
if ( isServerObject() && mActionAnimation.action >=PlayerData::NumTableActionAnims )
Con::executef(mDataBlock,3,"animationDone",scriptThis());I'm not sure why my animation doesn't "qualify". does the animation need some sort of requirement before it'll send ? It looks like it only does it if the player is in a certain animation. Does your animation have to return to the root position or something? In the code, i can manually send animation done by removing the if, and my script functions work.
#5
06/18/2007 (5:25 am)
Most callbacks like that are called on the dataBlock like, "armor onCollision" or "armor onMount". Maybe you should try that.
#6
06/18/2007 (7:49 am)
The callback works, but it's the if statement that's preventing the callback from executing. so now i need to figure out what the requirements for an animation are to get that callback to execute. right now i'm just using a punch animation that doesnt start or end in the root position because i want to be able to return to different positions afterwards.
Torque Owner Dracola
I looked around the documentation for more detailed info but I couldn't find any links. Hopefully someone know where to find an engine call list.