It's possible to store FPS value in a variable?

Hello guys I would like to know if it's possible to check the average fps of the player.

I know that FPS oscillates a lot, but I wondered if maybe I could store its values in variables, (I would store like 50~100 variables xD) and then I would be able to average these values.

Thank you very much in advance!
👋
This script will return the current FPS, rounded to the nearest integer:
Code:
Math.round(Graphics._fpsMeter.fps)
In general RMMV's FPS Meter object is a member of the Graphics class: Graphics._fpsMeter.
If needed you can find details on its various properties/methods over here: https://github.com/Darsain/fpsmeter
Not sure how savvy you are with JavaScript, but you may be able to use a single variable to store an array of values if time-averaging is important. 🙂
Hello @caethyril Thank you so much for answering!

Math.round(Graphics._fpsMeter.fps)

Awesome!! This worked perfectly!! Thank you very much!!

Not sure how savvy you are with JavaScript, but you may be able to use a single variable to store an ​
array​
of values if time-averaging is important. ​
🙂​

I´m very bad with codes. I have no idea how to do this xD
But it looks so much better using this array idea.
Please could you help me make this script? Please be very specific on how to do it XD

About the average time. I thought about recording 5 seconds of FPS data in every 30 seconds of gameplay.


I don't want to bother you ok. The script you gave me is already awesome!
Thank you so much!!
Hmm, I think this belongs better in the Javascript subforum.

I've moved this thread to Learning Javascript. Thank you.



EDIT: Also, is your inquiry finished? If so you can request the thread to be closed.
Sorry about that @MushroomCake28. Please keep the thread open in case caethyril help me with the array thing.
Thank you!
  1. OK, first of all you can set up (a.k.a. "initialise") an array using Control Variables > Set > Script > []. Yes, just a pair of square brackets. Now that variable is an empty array, waiting to be filled with values! 😤

  2. To add values to an array, you can use the push method. Let's say your array is in variable #1, then you could have this in a Script command:
    JavaScript:
    // Get the value
    var value = Math.round(Graphics._fpsMeter.fps);
    // Push it into the array (variable #1, change as appropriate)
    $gameVariables.value(1).push(value);
    (The lines that start with // are comments: they have no effect on the actual code.)

    You can use this in, say, a Parallel-trigger event to push a new reading into the array every X frames, e.g.
    Code:
    ◆Comment:Parallel trigger processes once per frame...
    ◆Script:var value = Math.round(Graphics._fpsMeter.fps);
    :      :$gameVariables.value(1).push(value);
    ◆Comment:Record one value every 6 frames~
    ◆Wait:6 frames
    Actually, now that I've written this I realise that Parallel events only work on the map, so this approach is quite limited. If you want to sample the framerate on menus etc then I'm pretty sure you'll need a plugin. 😴

  3. Lastly: calculating an average (the mean, right?). Here are a couple of options to do so, they're equivalent:
    Spoiler: Code stuff
    1. JavaScript:
      // Get array
      var arr = $gameVariables.value(1);
      // Calculate sum by looping through all array entries
      var sum = 0;
      var count = arr.length;
      for (var n = 0; n < count; n++) sum += arr[n];
      // Set variable #2 equal to sum / count, rounded to nearest integer
      $gameVariables.setValue(2, Math.round(sum / count));
    2. JavaScript:
      // Get array
      var arr = $gameVariables.value(1);
      // Calculate mean via reduce method (different syntax, same effect)
      var mean = arr.reduce(function(a, c) {
        return a + c;
      }, 0) / arr.length;
      // Assign result to variable #2, rounded to nearest integer
      $gameVariables.setValue(2, Math.round(mean));
    These options are both designed to be used in a Script command. Either way, you should now have a variable with a mean value! 😂

(Not sure if that's specific enough, or even what you were trying to do, but hopefully it helps~ 😅)
Hello @caethyril thank you so much for answering!

I'm sorry I got stuck in the part 2 xD

1:
part 1.jpg
Here at "script" I can just fill 1 line.
So I created a script below:

part 2.jpg


If I start the game this way, this happens:
part 3.jpg

Sorry I must have done everything wrong. Could you help me please, again? xD

Thank you very much in advance!


Actually, now that I've written this I realise that Parallel events only work on the map, so this approach is quite limited. If you want to sample the framerate on menus etc then I'm pretty sure you'll need a plugin.
This is not a problem, I will put it on a common event.

What I need is to know how is the game perform during the user’s gameplay.
If the fps is low, I can take some actions and decrease some effects and events during the game. The game will vary depending on the player's cell phone fps.
For part 1: you need to type [] in the Script box, don't just leave it empty. 😛

For part 2: I suggest removing the unnecessary zero in front of 339, i.e. use this script call instead:
JavaScript:
// Get the value
var value = Math.round(Graphics._fpsMeter.fps);
// Push it into the array (variable #339, change as appropriate)
$gameVariables.value(339).push(value);
Having a leading zero on integers in JavaScript can cause unexpected behaviour and/or errors. Best to be on the safe side just in case! 🙏

Also, you'll probably want to put step 1 in a separate event, otherwise it'll clear the array each time the Parallel event triggers, meaning you'll never get more than one value in the array. 😅
AWESOOOME! It worked!
Thank you very much again and sorry to bother you!
@thalesgal I take it this fully answers your thread?
@MushroomCake28 yes! Sorry I forgot to report!
Thank you!!

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/its-possible-to-store-fps-value-in-a-variable.117453/