playMaker

Author Topic: Constant Drain  (Read 1511 times)

kiramarshiku

  • Playmaker Newbie
  • *
  • Posts: 10
Constant Drain
« on: April 11, 2017, 02:48:01 PM »
I'm having issues figuring this out and I wanted to ask for some help. Basically I want to set up an FSM that will constantly drain a global float variable and when it gets to a number have it also drain another variable. Basically it's going to be like a needs system and when your hunger gets less then a number I want it to start draining weight. However I don't want any of my variables to be less then one. Could anyone help me with this? Also I have a button that when you click it hunger goes up but I want to disable it when it's maxed out. Is there a way for it to disable the button and then test the float again only when it's changed? If I just send it directly back to the test it creates a loop.

ToxicFrog

  • Beta Group
  • Full Member
  • *
  • Posts: 139
Re: Constant Drain
« Reply #1 on: April 11, 2017, 05:31:25 PM »
You could have the FSM compare the float to zero, and if it is equal or less than zero, stop the draining action.

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Constant Drain
« Reply #2 on: April 12, 2017, 03:35:24 PM »
Let's suppose you do it like this:

Start with 100 Hunger, wait 5 seconds and then substract 1 Hunger, and loop this. If Hunger goes below 50, go to next loop, which is basically the same, but this also substracts 1 Morality. If Hunger goes below 20, then go to a third loop, which also substracts 1 Hunger and 1 Morality with each tick, but also substracts 1 Sanity. You can clamp the variables so they never go below 1. And you can use the wait state (of the 5 seconds) to also check whether the variables are less than X and then go to some specified event.

Depending on how fancy you want to go, you can also split it up and run each of these stats in their own FSM. You then lead the START to an empty idle event that does nothing and just sits there. On the side, you create the loop which gets activated with a global event, let's call it "GO". You can trigger this from the Hunger FSM, e.g. if Hunger is below 50 trigger "GO" in "FSM Morality" which then does the ticking, etc.

Another neat trick is to take advantage of the state action order. You can simply put a float or int compare on top of the state, and say that if your value is below 1 execute "death" (or whatever you have). You can use a global event in there, so that you don't even need to link spaghetti all over your FSM, i.e. should the value go below 1, trigger "DEATH" (global event), and then in a corner of the same FSM you have a state that starts with "DEATH".

Hope that gives you some ideas.
« Last Edit: April 12, 2017, 03:40:14 PM by Thore »