[RGSS3] Call every second

Okay first I would like to thank you all for helping me with even the small things!


Second I would just like to say that I am trying to find these things before asking.


Alright so here's what I'm trying to do, I'll show it in code.


The things that are # are commented, I know that.


To check frames I think it's Graphics.frames()???


class RunEverySecond
def initialize()
@runthis = 0
end

def update()
super
#if @framespassed == 60
@runthis += 1
#end
end
end


Thanks for any help!
You can use:

Code:
if Graphics.frame_count % 60 == 0
You can use:



if Graphics.frame_count % 60 == 0

Ooooohhhhh, that's the code...


But how would I get this script to run when the map loads?


would I


class Game_Map


then add everything inside that or


class Scene_Base


I don't know what would call it when the map loads.
class Game_Map
alias 😮ld_setup :setup
def setup(map_id)
old_setup(map_id)
if Graphics.frame_count % 60 == 0
# Your Code
end
end


What this does is:

  1. Create an alias to the setup method of the Game_Map class (alias 😮ld_setup :setup)
  2. Declare a new method called setup, replacing the existing one (def setup)
  3. Calls the old method through the alias (old_setup)
  4. Adds new code

Basically you're replacing the old "setup" method with a new one. The new method executes the old one + your new code.
class Game_Map
alias 😮ld_setup :setup
def setup(map_id)
old_setup(map_id)
if Graphics.frame_count % 60 == 0
# Your Code
end
end


What this does is:

  1. Create an alias to the setup method of the Game_Map class (alias 😮ld_setup :setup)
  2. Declare a new method called setup, replacing the existing one (def setup)
  3. Calls the old method through the alias (old_setup)
  4. Adds new code

Basically you're replacing the old "setup" method with a new one. The new method executes the old one + your new code.

Ahhhhh, that makes sense, thanks a ton!
Hm, sorry to bother again however it seems when I


alias 😮ld_update :update


I get an error in Scene_Map?


Which is weird because this is in Game_Map


Script 'Scene_Map' line 89: ArgumentError occurred.


wrong number of arguments (1 for 0)


  def update_for_fade
    update_basic
    $game_map.update(false) #This is where the error is
    @spriteset.update
  end
Just looking at the error message, I think it's because you wrote $game_map.update(false). It's possible that $game_map.update() doesn't take arguments, so if you deleted "false" it would run, though I'm not sure if it would run the way you originally intended. 


Edit: again, I could be entirely off, but based on the error message that does seem to be the issue.
Just looking at the error message, I think it's because you wrote $game_map.update(false). It's possible that $game_map.update() doesn't take arguments, so if you deleted "false" it would run, though I'm not sure if it would run the way you originally intended. 


Edit: again, I could be entirely off, but based on the error message that does seem to be the issue.

Oh sorry I don't think I said that right, that script is actually from Scene_Map, not my code.


My code:

Code:
class Game_Map
  alias :old_setup :setup
  def setup(map_id)
    old_setup(map_id)
    msgbox_p(Graphics.frame_count)
    if Graphics.frame_count % 60 == 0
      updateplrneeds
    end
  end
  
  alias :old_update :update
  def update
    if Graphics.frame_count % 60 == 0
      updateplrneeds
    end
  end
  
  def updateplrneeds
    if Graphics.frame_count % 60 == 0
      if @plrHunger > 0
        @plrHunger -= 1
      end
      if @plrThirst > 0
        @plrThirst -= 1
      end
      if @plrSleep > 0
        @plrSleep -= 1
      end
      if @plrPhysicalStress > 0
        @plrPhysicalStress -= 0.1
      end
      if @plrMentalStress > 0
        @plrPhysicalStress -= 0.1
      end
      msgbox_p(@plrHunger)
    end
  end
end
You didn't include the params of the update method.
You didn't include the params of the update method.

Oh my goodness, I don't know how I missed that. Thank you!


Edit: Annnnnnnd I just realised how stupid I am, thanks again.

Original thread: https://forums.rpgmakerweb.com/threads/rgss3-call-every-second.63276/