Hi guys, I want to ask you about a beginer dilema that I have. It’s about the code structure.
I have a function that is triggered when the player pawn is hit. In this function I execute several things.
function Hit()
{
thing#1
thing#2
thing#3
thing#4
thing#5
}
With the function implemented this way, all the 5 things will be executed at the same time.
Let’s say that the thing#3 is an interpolation operation that will take 1 second to finish and I want the thigs #4 and #5 to be executed once finished the thing#3.
How do you recommend to structure the code to achieve this?
I made somthing like this, it’s working but I’m not sure it’s the best way in terms of good practices:
function Hit1()
{
thing#1
thing#2
thing#3 with a callback to Hit2()
}
function Hit2()
{
thing#4
thing#5
}
I don’t like it because I’m splitting the Hit logic in various functions just to handle the timings and delays of the events that occur inside. I made the recursive version but still feel that’s not right.
function Hit(iteration)
{
switch(iteration)
{
case 1:
thing#1
thing#2
thing#3 with a callback to Hit(2)
break;
case 2
thing#4
thing#5
break;
}
}
Any advice?
(Footnote, for context purposes, I’m trying to implement a kind of MortalKombat fatality mechanic, this is why the Hit event handling is so complex)