Beginner needs help with a Hunger system. (preferred: NO plugins)

This is my first time on a forums page.. So please forgive me if I do something wrong. (Formatting, code-wise, etc etc.)
I have 0 coding experience (At the most I understand logic gates, and the basics of RMMV.)
I'm trying to make a timer that when reaching 0.. gives you a debuff. But an if gate is there, where if you already have that debuff, it gives you a different variant of the debuff, removing the first one. (Oliver woods is the main character's name.)
(This name is not intended to be related to any real person dead or alive.)

◆If:hungrytimer is ON ◆Loop ◆If:Oliver Woods is affected by Peckished ◆Change State:Oliver Woods, - Peckished ◆Change State:Oliver Woods, + Hungry ◆Text:None, Window, Bottom : :You're getting hungry. ◆ :Else ◆Change State:Oliver Woods, + Peckished ◆Text:None, Window, Bottom : :You could do with a snack.. ◆ :End ◆ :Repeat Above ◆ :Else ◆ :End
I know that the way I wrote it, It'll simply loop over and over again whilst the switch is on. (Or maybe even indefinitely!) But any attempt of adding a timer, Or a wait function has either resulted in the game spamming my character with the two debuffs and text boxes, or just 100% freezing the game. I originally tried to put this mess of code into the common events, and then in a hidden event box, which I've had set to both Autorun and parallel.
If someone could please help me and explain what I'm doing wrong I'd appreciate it!
Well, yeah, you've got an infinite loop there. You're constantly switching from one to the other. There is no waiting, and no check for what happens if the player is hungry, and as a result they're ALWAYS peckish, hungry or both.

Explain what you want to happen, without using terms like gate, debuff, etc. Explain it from the player's point of view. When do they get peckish? When do they get hungry? What happens after they're hungry? What makes them NOT peckish or hungry? How long between states?

When are you turning on the hungrytimer switch?
Well, It should take 3 minutes (Had it set to 10 seconds for debugging) to go from 'full to peckish', 'peckish to hungry', etcetera. I have food items that cure the debuff, Like rice, carrots, other crops, but I want it to also add a cooldown, like- for example if you have 1 second on the timer and you consume a food item, you would immediately go back down a hunger level. When the player is hungry or peckish, they only get affected in battle with reduced stats and capabilities, but when they're starving, its almost identical to the default poison effect
I think I answered those questions right?

EDIT: forgot to send it as a reply, sorry.
You could set a variable to 360 (6 minutes) at start and then reduce it by one each second (parallel event), wait time 60 frames, variable - 1, then check the variable, if it is still above 180, remove both buffs, if below 180 and above 0, add 1st debuff, if 0 or below, remove 1st debuff, add 2nd debuff and set the variable to 0. Then you can add a common event to your food to add 180 to the variable. That should work... or set the variable to 0 and let it count up, if you're planning on adding more states, and then let the food remove 180 from the timer when it is consumed

Something like these:
1681027842916.png

1681027723972.png

1681027733346.png


Add if hunger = 180, if hunger = 360 if you want to write some text, else it will be written every second. With this, it will take up to 1 second for the states to be automatically set if you consume food.
I'm not sure on the cooldown ... what happens if the player consumes a food item when they have more than 1 second on the timer? I assume they'd still go down a single hunger level?

Try this, but it may not be quite what you're after.

Two switches - one called hungertimer, the other called hungerreset.
One variable called hungercounter.
On every food item, make the damage formula look like this:
Code:
$gameSwitches.setValue(15, true); n
where 15 is the switch number for your hungerreset switch, and n is the HP gain that would normally be in the damage formula on its own.

On the event where you set hungertimer ON, also set hungercounter to 0 and hungerreset OFF.

Now a common event, set to parallel process, and conditioned by the hungertimer switch.

Spoiler
Code:
Wait 60 Frames
If Switch hungerreset is ON
  Control Switches: hungerreset = OFF
  Control Switches: hungercounter = 0
  If Player is affected by Starving
    Change State: Player - Starving
    Change State: Player + Hungry
  Else
    If Player is affected by Hungry
      Change State: Player - Hungry
      Change State: Player + Peckish
    Else
      If Player is affected by Peckish
        Change State: Player - Peckish
        Change State: Player + Full
      End
    End
  End
Else
  If Player is affected by Starving
  Else
    Control Variables: hungercounter + 1
    If Variable hungercounter >= 180
      Control Variables: hungercounter = 0
      If Player is affected by Hungry
        Text: You're STARVING!!!
        Change State: Player - Hungry
        Change State: Player + Starving
      Else
        If Player is affected by Peckish
          Text: You're getting hungry
          Change State: Player - Peckish
          Change State: Player + Hungry
        Else
          Text: You could do with a snack
          Change State: Player - Full
          Change State: Player + Peckish
        End
      End
    End
  End
End

It is deliberate that after the Else, there are no commands if the player is starving.

So what's happening above is that every second, it'll check if the player has eaten something. If they have, it will move them down a level and restart the timer.
If they haven't eaten and they're not starving (since there's no progression after starving - unless you want them to actually die of starvation), it'll add a second to the elapsed time.
If the elapsed time is 3 minutes or longer, it'll move them up a level, display the appropriate message, and restart the timer for the next 3 minutes.
These are my favourite types of systems to build.

Here's how I would put it together.

Parallel common event, has a 3 minute timer.
Every 3 minutes it checks your state and progresses it. If you wanted to add more states in between they would slot in easily.
1681039308688.png


When you eat run this common event.
Reduces your state by 1 stage, and resets the hunger timer to 0 so it won't tick over automatically. If you wanted to reduce the timer partially instead of resetting completely you can say subtract from the hunger timer variable however much you like rather than resetting to 0.
1681039392634.png
Thank you all so much! You all have good ideas but I think I'm going to try and do the Variables solution that Brogar suggested!
You could set a variable to 360 (6 minutes) at start and then reduce it by one each second (parallel event), wait time 60 frames, variable - 1, then check the variable, if it is still above 180, remove both buffs, if below 180 and above 0, add 1st debuff, if 0 or below, remove 1st debuff, add 2nd debuff and set the variable to 0. Then you can add a common event to your food to add 180 to the variable. That should work... or set the variable to 0 and let it count up, if you're planning on adding more states, and then let the food remove 180 from the timer when it is consumed

Something like these:
View attachment 258389
View attachment 258387
View attachment 258388

Add if hunger = 180, if hunger = 360 if you want to write some text, else it will be written every second. With this, it will take up to 1 second for the states to be automatically set if you consume food.
Thank you all so much! You all have good ideas but I think I'm going to try and do the Variables solution that Brogar suggested!
Adding to this however, Is there a way to make it visible to the player?
Adding to this however, Is there a way to make it visible to the player?
If you mouse over the text window from the Show Text event command, you'll see a list of escape codes you can use. You can display the value of any variable using \V.

If you want it to be persistently visible to the player as a HUD element, you can make different images for the different states of hunger and use the Show Image event command.

Just a few stray tips:
(Oliver woods is the main character's name.)
(This name is not intended to be related to any real person dead or alive.)
This isn't necessary (both halves). We can see that's the character's name from the event code 😉

And there's no reason to give any kind of disclaimer. That's a (nearly pointless) thing that television shows do just in case a random person tries to claim their fictitious story slandered them and sues.

◆If:Oliver Woods is affected by Peckished
Hopefully you've gotten it from the other responses, but the word is "peckish," not "peckished."

Good luck with your project!
There are three things worth mentioning, in regards to the solutions that have currently been suggested thus far.

The first thing is that common events don't run in battle, so the timer will not run during battle. This may actually be desirable behavior, but since the OP didn't mention their preferences in this regard, I figured it's worth bringing up.

Similarly, the timer will pause when the main menu is opened. Once again, that might be preferable, but I figured I'd mention it.

The other thing worth mentioning is that when the player transfers maps, it will interrupt the execution of the parallel common event, and then the event will start over from the beginning. This means that the timer will increasingly lose accuracy every time the player transfers maps. To reduce the loss of accuracy, I would recommend using a lower Wait than the 60 frames that have been suggested.
Adding to this however, Is there a way to make it visible to the player?
You could make it like this:
1681277929158.png

The only time it doesn't alert the player is when you eat something, you would have to alert the player within the food, using conditional branches when he is lower than 360 or 180, but you probably should also put a conditional branch in if he ate food and already was below 180, so there is a separate line for that. Something like this:
1681278382543.png
this is a topic i'd love to learn too.

Original thread: https://forums.rpgmakerweb.com/threads/beginner-needs-help-with-a-hunger-system-preferred-no-plugins.156524/