Difference between revisions of "Time"

From MiniScript Wiki
Jump to navigation Jump to search
(Created page with "<c>time</c> returns the number of seconds since the script started running. Category:Intrinsic Functions")
 
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 
<c>time</c> returns the number of seconds since the script started running.
 
<c>time</c> returns the number of seconds since the script started running.
 +
 +
See also: [[wait]], [[yield]]
 +
 +
== Example ==
 +
 +
This example waits some random amount of time, then measures how long it takes you to react to a prompt by pressing a key.  It does this by checking the value of <c>time</c> before (t0) and after (t1) the <c>[[key.get]]</c> call.  Subtracting t0 from t1 gives the number of seconds between those times.
 +
 +
<ms>
 +
print "Get ready to press any key..."
 +
wait 1 + 3*rnd
 +
print "GO!"
 +
t0 = time
 +
key.get
 +
t1 = time
 +
print "That took you " + (t1 - t0) + " seconds.  Nice job!"
 +
</ms>
 +
  
 
[[Category:Intrinsic Functions]]
 
[[Category:Intrinsic Functions]]

Latest revision as of 02:14, 13 May 2023

time returns the number of seconds since the script started running.

See also: wait, yield

Example

This example waits some random amount of time, then measures how long it takes you to react to a prompt by pressing a key. It does this by checking the value of time before (t0) and after (t1) the key.get call. Subtracting t0 from t1 gives the number of seconds between those times.

print "Get ready to press any key..."
wait 1 + 3*rnd
print "GO!"
t0 = time
key.get
t1 = time
print "That took you " + (t1 - t0) + " seconds.  Nice job!"