playMaker

Author Topic: Managers and multiply FSMs using them at the same time  (Read 4925 times)

DanielThomas

  • Beta Group
  • Full Member
  • *
  • Posts: 150
Managers and multiply FSMs using them at the same time
« on: October 21, 2019, 10:50:10 AM »
Hi,
So I'm having a hard time designing my managers in a way that won't be error-prone.
My issue is with managers that can be called from many other FSMs at the same time. Let me use a stats manager as an example. The manager is responsible for modifying the stats of the player, such as total damage and attack speed.

Let's say I have a weapon, and when I equip it the player's stats need to be modified. The weapon first sends an event to modify the total damage and then modify the attack speed.

How do I make sure the stats manager are finished with the first event. I can of course just use something simple as a bool test. But as this gets more complicated when there are other FSMs that can call the stats manager - such as buffs that add damage, curses that reduce damage, etc.
Also possible to just have the weapons themsleves modify that stats, but it gets harder to debug as you don't know what FSM modified the stats.
While it might be fairly low chance that it all happens on the same frame, it's still possible.

How would one go about designing this? Is it possible to somehow queue this up? Is it necessary?


EDIT: I might have my answer here:
https://hutonggames.com/playmakerforum/index.php?topic=13603.msg63269#msg63269
Which is basically to just set the data from the item itself and not use a manager.

« Last Edit: October 21, 2019, 11:52:02 AM by DanielThomas »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Managers and multiply FSMs using them at the same time
« Reply #1 on: October 21, 2019, 12:28:28 PM »
Hi.
A system that i use is to have weapons stats in a xml with a ID number., and build a list with Hash Tables, and use the ID as reference.

Then a active weapon can get the values it needs, using the id.

On hit the 'enemy' will get the stats from the weapon (or bullet)
Then check for any boosters or damage reductions.
Then calculate total and apply the damage.

DanielThomas

  • Beta Group
  • Full Member
  • *
  • Posts: 150
Re: Managers and multiply FSMs using them at the same time
« Reply #2 on: October 21, 2019, 01:23:46 PM »
@djaydino I get what you mean. I was more trying to figure out a way to have a central FSM that would handle that since I need the stats updated on equiping (to show stats in the UI).
How to you handle enemies hitting player? Do the enemies "remove" health from the player? In theory there could be several enemies hitting the player in the same frame so having a "On hit" FSM for the player could cause the same problem from my original post.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Managers and multiply FSMs using them at the same time
« Reply #3 on: October 21, 2019, 06:16:16 PM »
Hi.
In short i'm adding the damage to an array and check if array is empty

if not empty loop thru and apply damage on index 0 then remove index 0 and check again if empty.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Managers and multiply FSMs using them at the same time
« Reply #4 on: October 21, 2019, 06:17:00 PM »
Actually not a build in array, but Array List (Array Maker)

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Managers and multiply FSMs using them at the same time
« Reply #5 on: October 21, 2019, 08:43:06 PM »
The damage should be processed in a single frame, of which there are 60 per seconds. Unless your game play has lots of rapid damage events (several every second), I’d say you worry too much. Stats should also not change that quickly, usually, because you need to keep in mind that a human must understand what’s going on. The better solution is tweaking the play so that changes are clear and intelligible.

DanielThomas

  • Beta Group
  • Full Member
  • *
  • Posts: 150
Re: Managers and multiply FSMs using them at the same time
« Reply #6 on: October 22, 2019, 05:05:22 AM »
@Thore Thanks for the input. I would need to disagree though, one would be knowingly leaving it to chance, which I don't think is a good approach?

I'm not sure what you mean with stats shouldn't change quickly. It's more about the idea of having a system that can handle this. Stats could change in many different ways, such as equipment, getting a buff or debuff from enemies and maybe some other events. In theory all this could happen at the same frame: Payer equip an item, an enemy cast a debuff and maybe an old buff runs out. So this would require the system to be able to handle 3 stats modifying events in the same frame.

The best idea I have so far is, as djaydino mentioned, would be to work with arrays and hash tables and queue everything up for the manager. I was just hoping there might be a standard for how to do this.
BUT with that said, the Unity tutorials I've seen just sets the stat directly from the item itself, not through a manager.
« Last Edit: October 22, 2019, 05:09:04 AM by DanielThomas »

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 772
Re: Managers and multiply FSMs using them at the same time
« Reply #7 on: October 22, 2019, 06:21:33 AM »
With several enemies attacking the player, or the player tanking a rain of hits, either you let each enemy, logically instances of a model, handle the health reducing locally, or you have them send an "order" with some data attached to it (like damage) and process all that through a central FSM, the way dino spoke of, by filling an array with such orders: a centralize array called "Damage" and sources of damage adding their own damage to it.
For more information about the origin of the damage, you may use a Hash table instead, so you can use the key of any new entry to know what is the source of the damage by using an ID as the key, but it means you must develop a little system to have each enemy (or anything else dealing damage) to generate its own ID.
That's something you can even log.

DanielThomas

  • Beta Group
  • Full Member
  • *
  • Posts: 150
Re: Managers and multiply FSMs using them at the same time
« Reply #8 on: October 23, 2019, 07:37:15 AM »
Thanks for the input, this is what I suspected.
I'm using enum for stats type, so I'm guessing I will need a couple of arrays: One with stats type, one with the modification value and one with bools to tell if it's a value or a percentage modification. And just keep them all at the same index.

I'll give it a go and see how messy it gets.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Managers and multiply FSMs using them at the same time
« Reply #9 on: October 23, 2019, 10:36:17 AM »
Hi.
For our weapons i use xml and @ runtime set them into hash tables.
the reference i use for the weapon/item ID and then inside it i have all the stats for that weapon.

the nice thing with hash tables is that you can use several types in 1 hash table.
So you can have a key using an int, a key using a string, a key with a bool etc.

I am planning for some tutorials, but due to overload of work it can take a while to release them.

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 772
Re: Managers and multiply FSMs using them at the same time
« Reply #10 on: October 25, 2019, 06:13:58 AM »
the nice thing with hash tables is that you can use several types in 1 hash table.
So you can have a key using an int, a key using a string, a key with a bool etc.

Yeah, that's true for arrays too and that's something that is little known, for the simple fact that when you add an Array List or Hash Table as a component to a Game Object, you see the option to preset a given number of entries, but they'll all be of the same type, so you tend to think that you're stuck with one type of variable per array/table, but it's not true.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Managers and multiply FSMs using them at the same time
« Reply #11 on: October 25, 2019, 09:08:45 AM »
Hi.
I actually did not know you could do this with arrays as well!