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

Status
Not open for further replies.

thalesgal

Veteran
Veteran
Joined
Dec 23, 2016
Messages
193
Reaction score
41
First Language
Portuguese
Primarily Uses
RMMV
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!
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
1,510
Reaction score
992
First Language
EN
Primarily Uses
RMMV
:kaohi:
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. :)
 

thalesgal

Veteran
Veteran
Joined
Dec 23, 2016
Messages
193
Reaction score
41
First Language
Portuguese
Primarily Uses
RMMV
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!!
 

MushroomCake28

KAMO Studio
Global Mod
Joined
Nov 18, 2015
Messages
2,597
Reaction score
3,782
First Language
English
Primarily Uses
RMMV
Hmm, I think this belongs better in the Javascript subforum.

I've moved this thread to Learning Javascript. Please be sure to post your threads in the correct forum next time. Thank you.



EDIT: Also, is your inquiry finished? If so you can request the thread to be closed.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
1,510
Reaction score
992
First Language
EN
Primarily Uses
RMMV
  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! :kaopride:

  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. :kaoslp:

  3. Lastly: calculating an average (the mean, right?). Here are a couple of options to do so, they're equivalent:
    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! :kaojoy:

(Not sure if that's specific enough, or even what you were trying to do, but hopefully it helps~ :kaoswt:)
 

thalesgal

Veteran
Veteran
Joined
Dec 23, 2016
Messages
193
Reaction score
41
First Language
Portuguese
Primarily Uses
RMMV
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.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
1,510
Reaction score
992
First Language
EN
Primarily Uses
RMMV
For part 1: you need to type [] in the Script box, don't just leave it empty. :p

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! :kaothx:

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. :kaoswt2:
 

thalesgal

Veteran
Veteran
Joined
Dec 23, 2016
Messages
193
Reaction score
41
First Language
Portuguese
Primarily Uses
RMMV
AWESOOOME! It worked!
Thank you very much again and sorry to bother you!
 

MushroomCake28

KAMO Studio
Global Mod
Joined
Nov 18, 2015
Messages
2,597
Reaction score
3,782
First Language
English
Primarily Uses
RMMV

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.

 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Ladies and Gentlemen, I can't act like things will be ok anymore. It needs to be said: We have a Pandemic...
Release version of Pillow Hero is out on windows now! --> https://bit.ly/2USHKLv
Stream will be live shortly! Feeling like doing some Minecraft instead of DK64 since it has been a bit! Feel free to drop by!
I have a situaaaaaaaation!!!!
Alright guys, I decided to be nice and let you use my instant map creator plugin entirely for free! :LZSexcite:

Forum statistics

Threads
95,551
Messages
930,035
Members
125,836
Latest member
RaizenRadoriam
Top