[VXA] Store current frame rate into a variable?

I know RGSS has a Graphics.frame_rate member, but that just returns the maximum FPS cap of the game.

Is there any way of reading the current frame rate and storing it into a variable? I figured this would be possible since the .exe already does this by pressing F2.
I can't help you with this, unfortunately, but I am extremely interested in what application you intend for this, if you don't mind my asking.
I can't help you with this, unfortunately, but I am extremely interested in what application you intend for this, if you don't mind my asking.

I need to make an event that synchronizes almost perfectly with a BGM. Unfortunately, in RPG Maker there's no such thing as real audio synchronization.

So to minimize any possible delays, I'd just use the framerate as a factor to slow down / sped up the visual part. For example, if the FPS is 60 the animation will take 1 frame to go to the next pattern. But if the FPS is 30, the animation will take 2 frames to go to the next pattern.

That way the visual part can keep up with the BGM. I could also try using the "position" property of the Audio module and make a really big elsif chain, but that's the last thing I'd want to do.
That is...a very logical application. I've struggled with BGM synchronization too but I'd never actually come as close as you have to developing a solution. For some reason my mind immediately leapt to the silliest application possible, like skills that inflict damage based on frame rate or something :elwink:
frame rate and storing it into a variable
I don't know if this would be the current, but it's the frame rate
Graphics.frame_rate

Look in Game_System -> def playtime
I will go straight to tell you that audio synchronization (or synchronization in general) is hell in the RGSS engine. But I will answer your question.

For starters, no, there is no simple script call for it. But... this MIGHT work.
Code:
class << Graphics
  
  alias update_fps update
  def update
    @time ||= Time.now
    @last_frame_count ||= frame_count 
    @fps ||= frame_rate
    update_fps
    if @time != Time.now
      @time = Time.now
      @fps = frame_count - @last_frame_count
      @last_frame_count = frame_count
    end
  end
  
  def current_fps
    @fps
  end
  
end
To get the current fps, use Graphics.current_fps

Diclaimer:
Not tested.
I will go straight to tell you that audio synchronization (or synchronization in general) is hell in the RGSS engine. But I will answer your question.

For starters, no, there is no simple script call for it. But... this MIGHT work.
Code:
class << Graphics
 
  alias update_fps update
  def update
    @time ||= Time.now
    @last_frame_count ||= frame_count
    @fps ||= frame_rate
    update_fps
    if @time != Time.now
      @time = Time.now
      @fps = frame_count - @last_frame_count
      @last_frame_count = frame_count
    end
  end
 
  def current_fps
    @fps
  end
 
end
To get the current fps, use Graphics.current_fps

Diclaimer:
Not tested.

I'm afraid it doesn't work, or maybe I'm not using it as intended.

1610425530681.png


This is my console output of the different variables in real-time. As you can see, the last_frame_count and frame_count variables are being updated at the same time (with a 1 frame difference tho, and that's why fps is 1).

I don't wanna take too much of your time tho, if this is too much trouble, then I may as well try to modify the Audio module to have an acceptable "position" property (without exaggerately big numbers). That way instead of using framerate factors I could directly use the BGM current position.
or maybe I'm not using it as intended.
This is probably the case.

This is my console output of the different variables in real-time.
The FPS is supposed to be updated per second, not in real-time.
You're checking it in real-time, or to be precise in every frame. It makes sense that the fps is displayed as 1.

If anything, you could try to break down this particular fps display mod script from an unknown scripter instead of using mine. Despite being in my Github, it isn't actually mine.
It uses a clever trick to record a hiccup during 60 frames per second. If there is no hiccup, it displays 60 FPS. If there is a hiccup, the FPS will drop.

Use script call Graphics.fps to get the current fps.

EDIT:
then I may as well try to modify the Audio module to have an acceptable "position" property (without exaggerately big numbers). That way instead of using framerate factors I could directly use the BGM current position.
I hate to break you but how the audio position works is currently unknown. It isn't based on sample, or timestamp, or anything. You are free to try, but trying to synchronize things in the RGSS engine is near impossible unless you want to try to create your own Audio module.

By any chance, are you trying to make a rhythm game?
This is probably the case.


The FPS is supposed to be updated per second, not in real-time.
You're checking it in real-time, or to be precise in every frame. It makes sense that the fps is displayed as 1.

If anything, you could try to break down this particular fps display mod script from an unknown scripter instead of using mine. Despite being in my Github, it isn't actually mine.
It uses a clever trick to record a hiccup during 60 frames per second. If there is no hiccup, it displays 60 FPS. If there is a hiccup, the FPS will drop.

Use script call Graphics.fps to get the current fps.

EDIT:

I hate to break you but how the audio position works is currently unknown. It isn't based on sample, or timestamp, or anything. You are free to try, but trying to synchronize things in the RGSS engine is near impossible unless you want to try to create your own Audio module.

By any chance, are you trying to make a rhythm game?

That works fine. Thanks a lot!
Thread closed

Original thread: https://forums.rpgmakerweb.com/threads/vxa-store-current-frame-rate-into-a-variable.132129/