playMaker

Author Topic: Count UP timer  (Read 948 times)

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 772
Count UP timer
« on: December 12, 2020, 02:09:43 PM »
There's an issue with the reset on enter bool.
I have a simple FSM with two states.

Starting state has:
- Count Up Timer; no reset on enter, real time, stores float in "time".
- Bool Change; checks bool "reduce", if true goes to second state.

Second state has:
- Set Bool Value; with "reduce" to false.
- Float Subtract; time is reduced by x (seconds). Is either defined in this FSM or another (then uses Set Fsm Float).

Then it returns into the first state.

Another FSM changes "reduce".

Instead of the timer resuming with the altered time value, it restarts from zero despite "reset on enter" being false.

Code: [Select]
public override void OnEnter()
{
startTime = FsmTime.RealtimeSinceStartup;
if(restartOnEnter.Value)
{
timer = 0f;
}
}

startTime is a private float, I think it might be better if it were exposed as a FsmFloat.
Also, I wonder if the problem is in this line:

Code: [Select]
startTime = FsmTime.RealtimeSinceStartup;

Switching "Real time" to false (off in other words) also allows the reset option to work. Otherwise it's impossible to use this boolean to reboot the action.

PS: There's a typo in Float Sub_tract's name.
« Last Edit: December 12, 2020, 02:25:47 PM by Broken Stylus »