This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-04-15 19:00:09

chanmanpartyman
Scratcher
Registered: 2011-05-30
Posts: 500+

FPS Script

This is in Frames per Second, not feet per second  tongue  Ahem, chipguy  tongue  Jk.
Here ya' go people:

when gf clicked
forever
 set [FPS v] to ((1)/(timer))
 reset timer
You can tell this is an accurate showing because:
when gf clicked
forever
 change [frame v] by (1)
 if < (timer) > [1] >
  set [FPS v] to (frame)
  set [frame v] to (0)
  reset timer
 end
The second one is rounded. The first one is exact and refreshed every frame, not every second like the second one. Hope you find this useful!

Last edited by chanmanpartyman (2012-04-15 20:57:54)

Offline

 

#2 2012-04-15 19:14:52

chipguy
Scratcher
Registered: 2009-09-09
Posts: 500+

Re: FPS Script

nice script! i wonder how someone would use it, though.


http://scratch.mit.edu/static/projects/chipguy/2919121_sm.png by yours truly  big_smile

Offline

 

#3 2012-04-15 19:29:15

beyblade4
Scratcher
Registered: 2011-08-02
Posts: 1000+

Re: FPS Script

what is this for?


http://blocks.scratchr.org/API.php?user=beyblade4&amp;action=projects&amp;type=newest&amp;return=image&amp;num=NUMBER

Offline

 

#4 2012-04-15 19:31:59

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: FPS Script

beyblade4 wrote:

what is this for?

Usually someone uses an FPS simply for displaying it to the user...it allows them to know the speed the program is running at.  You could use the FPS to possibly try and keep your project going at a constant FPS by adding a system that waits until it's to a set value as well  smile


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#5 2012-04-15 19:41:55

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: FPS Script

chipguy wrote:

nice script! i wonder how someone would use it, though.

For instance, if you want a sprite to move at a constant speed in real time, you could make it move at a speed that is a function of the FPS (if that makes sense).  The less frames per second you have, the faster the sprite moves per frame; this means that in "real time" it moves a constant speed.

Having said all of that, I've never used it in Scratch  smile


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#6 2012-04-15 20:15:35

chipguy
Scratcher
Registered: 2009-09-09
Posts: 500+

Re: FPS Script

oh! this is frames per second! i though you were doing feet per second!


http://scratch.mit.edu/static/projects/chipguy/2919121_sm.png by yours truly  big_smile

Offline

 

#7 2012-04-19 08:08:36

jontmy00
Scratcher
Registered: 2011-11-28
Posts: 1000+

Re: FPS Script

Kind of useful. I was looking for this to find the FPS of my projects.  smile


FOR ALL THE NEWS ON UPDATES FOR SIMPLISTICRAFT, CLICK HERE.

Offline

 

#8 2012-04-19 08:58:59

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: FPS Script

I thought this was a first-person shooter  tongue


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#9 2012-04-23 10:50:06

AOEmaster
Scratcher
Registered: 2012-04-21
Posts: 18

Re: FPS Script

Hey thanks for the scripts, chanmanpartyman!
But how do you use them in a project, do you put the script on the gun or background?

Offline

 

#10 2012-04-23 11:32:55

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: FPS Script

It is especially useful if you want to create a project that is meant to run in turbo mode, and you want to run the project at a steady 30 frames per second, for example.  You run the game loop that gathers input from the user, etc. (this gives you faster responses), but you only update the position of the sprite when the FPS script returns a value greater than 30. 

For example:

when gf clicked
set [Framerate v] to (30)
forever
  broadcast [GetKeyPresses v] and wait // The program collects keypresses.  
  broadcast [Update v] and wait // The program carries out any calculations needed.  
  set [FPS v] to ((1)/(timer))
  if < (FPS) > (Framerate) >
    broadcast [Draw v] and wait // Game elements change position on screen.  
  end
end

Last edited by amcerbu (2012-04-23 11:34:10)

Offline

 

#11 2012-04-23 12:22:31

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: FPS Script

It can also be used simply to check if the project is in turbo mode: run it a few times on non-turbo mode, check the peak fps, add this script:

when gf clicked
if <(fps) < [peak fps]>
say [I'm in turbo mode!]
else
say [I'm not in turbo mode...]
end

Last edited by Hardmath123 (2012-04-23 12:22:51)


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#12 2012-04-23 16:06:16

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: FPS Script

@Hardmath123- Wouldn't it be the opposite, because you would expect the framerate to go up in turbo mode? 

So...


when gf clicked
set [highestFramerate v] to (0)
repeat (10)
set [framerate v] to ((1)/(timer))
if <(framerate) > (highestFramerate)>
set [highestFramerate v] to (framerate)
end
reset timer
end
if <(highestFramerate) > (fpsTurbo)>
say [I'm in turbo mode!]
else
say [I'm not in turbo mode...]
end

Last edited by amcerbu (2012-04-23 18:44:10)

Offline

 

Board footer