Retrieving frame rate

How would one retrieve the frame rate in code? I’m making a function which shows stats about the game—graphics, performance, etc.—but I know not how to retrieve the frame rate. How would I do this?

2 Likes

There’s a built in way to do so, but I’m not sure how you can replicate that in makecode.

If your curious, go to the pause menu and enable “show stats”.

1 Like

Ok, this really depends on if you’re using blocks or JavaScript. You’ll need someone to make an extension for you in blocks, or you’ll need a few grey blocks. I found the code that sets the fps in the fps counter thingy:


It’s in Explorer → base → eventcontext.ts lines 76 - 107. It puts the fps into this variable, control.EventContext.lastStats, which is a string. You could get this value by doing something like parseInt(control.EventContext.lastStats.substr(4)) which just strips off the “fps:” part and then converts it to a number. If you’re making a display, you can probably just keep it as a string if you wanted to.

3 Likes