Current () (block)

Star.png This article was featured in November 2016 for providing the most helpful content.
Current ()
2.0 Current ().png
Category Sensing
Type Reporter
Introduced in 2.0

The Current () block is a Sensing block and a reporter block. It reports either the current local year, month, date, day of the week, hour, minutes, or seconds, depending on the argument. The block gets the data based on the user's computer's clock and set in 24-hour clock. The block was previously called Local () in early versions of the Scratch 2.0 alpha to make it clearer that it uses a user's local time.

The options in Current ().

It is one of two new date/time blocks in Scratch 2.0 so far. The other is Days Since 2000, which reports the amount of days since January 1, 2000.

Example Uses

This block can be used in some of the following ways:

  • Creating a clock or calendar
when gf clicked
forever
say (join (current [hour v]) (join [:] (join (current [minute v]) (join [:] (current [second v])))))
Warning Note: To have a changing background, use this script. Don't forget to add backgrounds labled Morning, Afternoon, and Night.
when gf clicked
forever
if <<(current [hour v]) > [5]> and < (current [hour v]) < [12]>>  then // You can use any range of hours you feel that qualify as morning.  This is 6-11 o'clock.
switch backdrop to [Morning v]
else
if <<(current [hour v]) > [11]> and < (current [hour v]) < [18]>>  then // You can use any range of hours you feel that qualify as afternoon.  This is 12 - 17 o'clock.
switch backdrop to [Afternoon v]
else
switch backdrop to [Night v] // These hours are based on the previous hours.  This is 18 - 5 o'clock.
end
end
say (join (current [hour v]) (join [:] (join (current [minute v]) (join [:] (current [second v])))))
  • Making something unavailable before or after a certain date
if <(current [year v]) < [2015]> then
  change [money v] by (1000)
else
  say [Sorry, but this feature is unavailable after 2014.]
end
  • Timestamps on a high-score list
add (join (join (join (join (join (join (join [Day:](current [day v]))[ ])(current [hour v]))[:])(current [minute v]))[|Highscore:])(Score)) to [Highscores List v]
Warning Note: When the output is less than 10, the hour, minute, and second blocks will report a single-digit unpadded number instead of a double-digit number, e.g. 05:09:03 will appear as 5:9:3.

This can be corrected with the following script:

if <(current [hour v]) < [10]> then
set [hour v] to (join [0] (current [hour v]))
else
set [hour v] to (current [hour v])
end
if <(current [minute v]) < [10]> then
set [minute v] to (join [0] (current [minute v]))
else
set [minute v] to (current [minute v])
end
if <(current [second v]) < [10]> then
set [second v] to (join [0] (current [second v]))
else
set [second v] to (current [second v])
end
say (join (hour) (join [:] (join (minute) (join [:] (second)))))

See Also

  • This page was last modified on 21 August 2017, at 22:55.