Resources Consumption Meter
#6
Since you mentioned a HUD, you might wanna learn how to easily implement a trigger that will properly update the HUD only once instead of every second or even a fraction of a second.

Code:
class MyHUD
  @@need_refresh = 0
  def self.need_refresh
    @@need_refresh
  end

  def self.need_refresh=(number)
    @@need_refresh = number
  end

  def update
    if @@need_refresh > 0
      refresh
      return @@need_refresh = 0
    end
  end
end

There were have a mock of a HUD, its update method only. (There are 2 other methods but we will ignore them for the time being.)

It will only redraw its contents IF and only IF the @need_refresh variable is equal to any number above 0. Once it got updated, it will set it to 0 so it can't be triggered over and over again.

How would you make sure it will ever update the stats when needed only?

Use something like the following:

Code:
class Game_Actor
  def hp=(new_hp)
    old_hp = self.hp
    super(new_hp)
    MyHUD.need_refresh = 1 if self.hp != old_hp
  end

  def sp=(new_sp)
    old_sp = self.sp
    super(new_sp)
    MyHUD.need_refresh = 2 if self.sp != old_sp
  end
end

As you can see, we are calling one of the unexplained methods of MyHUD class. It's a singleton method that calls a very specific class variable that can be used at any time, even from another classes or objects, i.e. from an actual Game_Actor alias one of the heroes!

That call will make sure that your HUD will only update itself when and only when the hero's HP or SP (or even both at the same time) activate it right after their values have changed.

By the way, I used a number instead of a boolean (true or false) because this way I do prevent the SP update to cancel an HP update for not having changed simultaneously.
"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9

Maranatha!

The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.

[Image: SP1-Scripter.png]
[Image: SP1-Writer.png]
[Image: SP1-Poet.png]
[Image: SP1-PixelArtist.png]
[Image: SP1-Reporter.png]

My Original Stories (available in English and Spanish)

List of Compiled Binary Executables I have published...
HiddenChest & Roole

Give me a free copy of your completed game if you include at least 3 of my scripts! Laughing + Tongue sticking out

Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE
Reply }


Messages In This Thread
Resources Consumption Meter - by Whisper - 05-27-2023, 01:26 AM
RE: Resources Consumption Meter - by kyonides - 05-27-2023, 01:59 AM
RE: Resources Consumption Meter - by DerVVulfman - 05-27-2023, 04:52 AM
RE: Resources Consumption Meter - by Kain Nobel - 05-27-2023, 08:59 AM
RE: Resources Consumption Meter - by Whisper - 05-27-2023, 10:17 PM
RE: Resources Consumption Meter - by kyonides - 05-27-2023, 10:43 PM
RE: Resources Consumption Meter - by Whisper - 05-29-2023, 03:51 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Custom meter problem daylights 13 16,146 08-12-2013, 03:34 AM
Last Post: daylights



Users browsing this thread: 2 Guest(s)