Real-Time Regeneration

Hi there! So I have been attempting to make a script that would regenerate stats in real-time (ie, on the overworld your health would slowly regenerate, in battle you would regain MP, etc). Unfortunately, despite my many efforts, I can't make it work.

Right now, my biggest priority is creating a simple script that would slowly give players TP in battle, so that the longer the battle lasted, the more complex skills they could use, yadda yadda. I tried doing:

def tp_gain while true do self.tp +=1 sleep(2) endendThis was under the game_battler class. Unfortunately, I couldn't get it to work. I am not sure if this is a problem with the code itself (I think it looks sound, but I could not code myself out of a wet paper bag) or a problem with calling the method. When I tried putting tp_gain into initialize, it caused problems with the actor class. What am I doing wrong? If someone doesn't want to write a whole script for me, that's fine, I would also take advice that could push me in the right direction. 

Right now, this is what I have:

def gain_tp time = $game_system.playtime  time += 2  update_tpenddef update_tp   while true do    if Time.now >= time    self.tp += 1    break elsif Time.now < time   return  endend  gain_tp end

Any advice? I apologize for my coding. I've only been coding a couple of months, and I understand I am very bad at it.
You need to let the game update by itself. There are many things updated when the game is running, so making a repeating block like that is not advisable.
If you want a realtime regeneration on map, this is one example:
 

Code:
class Game_Player    alias :init_x3587 :initialize  def initialize(*args)    init_x3587(*args)    @tp_regen_counter = 0  end    alias :update_x3587 :update  def update(*args)    update_x3587(*args)    update_regen_tp  end    def update_regen_tp    @tp_regen_counter = (@tp_regen_counter + 1) % 600 # 10 seconds    if @tp_regen_counter == 0      $game_party.members.each {|actor| actor.tp_grad_regen }    end  end  endclass Game_Actor < Game_Battler    def tp_grad_regen    self.tp += 1  end  end
I think he wants real-time regeneration inside battles

my biggest priority is creating a simple script that would slowly give players TP in battle, so that the longer the battle lasted,
But really, so if I for example just don't pick an action, I can rack up my TP? I don't think that is a nice idea, really...


and where did you put that code anyways? it should be inside a class or a module
Blame me with my own misunderstandings.... In that case, I'll just change the Game_Player to Scene_Battle.

Regen on real time might be useful for those real-time battle systems. I am not a fan of those systems though.
for things like ATB, yes... but he didn't say anything about that so for now I'm assume its for the normal battle system...
It is also useful in daily grind type of games where you have x amount of stamina/energy/force/etc and you can only do so many things per day.


For example, if TP were a requirement to do a quest or enter a dungeon, and TP replenishes based on time, you'd have to wait in order to gain access to it again. Or spend money to replenish it. In that case, you suddenly have a cash cow.
yeah, those would be... case in hand though, he wants to use it inside the battle scene 🙂
Thank you for everyone's insight! It's funny, but after struggling with this for two weeks, I actually came up with a solution a couple hours after posting. That's life for you. What I did was make a subclass of Game_Timer. I made a method that sets count based on certain variables (battler agility compared to average party agility is default) and at the end of the countdown, executes the action I wish. With a bit of fiddling, it can do whatever I need it to.

And yes, I am planning on using this for a variation on a ATB. Enemies will also regenerate tp over time, which is actually a handy way to control approximately how often they will use very powerful attacks.  So sitting on your duff will just screw you over if you aren't careful. Of course, this system still needs a lot of tweaking to be functional, but what I lack in skill, I make up for in persistence!

Thank you everyone for your input and some excellent ideas for thought.
you can simply use the TP regeneration Feature for that though (as long as your ATB still calls the turn_end methods somehow)... at least unless you need a lot more control...
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/real-time-regeneration.25599/