(Reorganizing Category:Scripting Tutorials...)
(Fixed blocks.)
 
(16 intermediate revisions by 12 users not shown)
Line 1: Line 1:
A '''countdown''' is something which would explain how many days (or another time form) are left until a certain event starts. Projects can also have countdowns too. Here's how to make one.
+
A '''countdown''' is a timer that reports how much time is left until an event will occur. Projects can also have countdowns too. This tutorial shows how to make one. Within the scope of this tutorial, the timer is counting down to an event at a specific date measured in days. Of course, timers can also be built to be compatible to seconds/minutes with either the built in [[timer]] feature or the [[Current Minute|minute]] block depending on what the project using it requires.
  
 
==List==
 
==List==
First, you need a [[List|list]]. A list is a feature which allows you too stall multiple values at once. Create a list called '''Dates''' or anything you want to call it.
+
First, a [[list]] is needed. A list is a feature which allows the program to stall multiple values at once. Create a list called '''Dates''' or anything else that is appropriate.
  
Okay, for each item in the list (except the last), it need to be the last date of the months before the month of the event. The first item will have the last date of the current month and the last one will have the date of the event. For example, you're making a countdown to [[Scratch Day]] 2015 and it's currently March.
+
For each item in the list (except the last), it needs to be the last date of the months before the month of the event. The first item will have the last date of the current month and the last one will have the date of the event. For example, a countdown to the next [[Scratch Day]] and it is currently March.
  
 
<scratchblocks>
 
<scratchblocks>
 
when gf clicked
 
when gf clicked
delete (all v) of [Dates v]
+
delete all of [Dates v]
 
add [31] to [Dates v]
 
add [31] to [Dates v]
 
add [30] to [Dates v]
 
add [30] to [Dates v]
Line 14: Line 14:
 
</scratchblocks>
 
</scratchblocks>
  
==Computing the countdown==
+
==Computing the Countdown==
Here, you now have the list but the countdown isn't complete! Create a [[Variable|variable]] called '''Days left''' (since you're using days) or whatever you want to call it.
+
There is now a list but the countdown is not finished. Create a [[variable]] called '''Days left''' (since the coder is using days) or something else if wanted.
  
Back to your list, you need to have this script which completes the countdown. The first month will be the current month and the last month will be the month of the event. Here, you'll use March (3) as the first one and May (5) as the last one.
+
Back to the list, the script below will need to be added to complete the countdown. The first month will be the current month and the last month will be the month of the event. In this case, March (3) is used as the first one and May (5) is used as the last one.
  
 
<scratchblocks>
 
<scratchblocks>
 
when gf clicked
 
when gf clicked
if <(current [month v]) = (3)>
+
if <(current [month v]) = (3)> then
replace item (1 v) of [Dates v] with ((item (1 v) of [Dates v]) - (current [date v]))
+
replace item (1) of [Dates v] with ((item (1) of [Dates v]) - (current [date v]))
 
else
 
else
replace item (1 v) of [Dates v] with (0)
+
replace item (1) of [Dates v] with (0)
if <(current [month v]) = (4)>
+
if <(current [month v]) = (4)> then
replace item (2 v) of [Dates v] with ((item (2 v) of [Dates v]) - (current [date v]))
+
replace item (2) of [Dates v] with ((item (2) of [Dates v]) - (current [date v]))
 
else
 
else
replace item (2 v) of [Dates v] with (0)
+
replace item (2) of [Dates v] with (0)
if <(current [month v]) = (5)>
+
if <(current [month v]) = (5)> then
replace item (3 v) of [Dates v] with ((item (3 v) of [Dates v]) - (current [date v]))
+
replace item (3) of [Dates v] with ((item (3) of [Dates v]) - (current [date v]))
 
end
 
end
 
end
 
end
 
end
 
end
set [Days left v] to ((item (1 v) of [Dates v]) + ((item (2 v) of [Dates v]) + (item (3 v) of [Dates v])))
+
set [Days left v] to ((item (1) of [Dates v]) + ((item (2) of [Dates v]) + (item (3) of [Dates v])))
 
</scratchblocks>
 
</scratchblocks>
  
Congratulations! You created your own countdown!
+
[[Category:Scripting Tutorials|Countdown]]
 
 
[[Category:How To Pages|Create a Countdown]]
 
[[Category:Scripting Tutorials|Create a Countdown]]
 

Latest revision as of 06:43, 9 May 2021

A countdown is a timer that reports how much time is left until an event will occur. Projects can also have countdowns too. This tutorial shows how to make one. Within the scope of this tutorial, the timer is counting down to an event at a specific date measured in days. Of course, timers can also be built to be compatible to seconds/minutes with either the built in timer feature or the minute block depending on what the project using it requires.

List

First, a list is needed. A list is a feature which allows the program to stall multiple values at once. Create a list called Dates or anything else that is appropriate.

For each item in the list (except the last), it needs to be the last date of the months before the month of the event. The first item will have the last date of the current month and the last one will have the date of the event. For example, a countdown to the next Scratch Day and it is currently March.

when gf clicked
delete all of [Dates v]
add [31] to [Dates v]
add [30] to [Dates v]
add [9] to [Dates v]

Computing the Countdown

There is now a list but the countdown is not finished. Create a variable called Days left (since the coder is using days) or something else if wanted.

Back to the list, the script below will need to be added to complete the countdown. The first month will be the current month and the last month will be the month of the event. In this case, March (3) is used as the first one and May (5) is used as the last one.

when gf clicked
if <(current [month v]) = (3)> then
replace item (1) of [Dates v] with ((item (1) of [Dates v]) - (current [date v]))
else
replace item (1) of [Dates v] with (0)
if <(current [month v]) = (4)> then
replace item (2) of [Dates v] with ((item (2) of [Dates v]) - (current [date v]))
else
replace item (2) of [Dates v] with (0)
if <(current [month v]) = (5)> then
replace item (3) of [Dates v] with ((item (3) of [Dates v]) - (current [date v]))
end
end
end
set [Days left v] to ((item (1) of [Dates v]) + ((item (2) of [Dates v]) + (item (3) of [Dates v])))
Cookies help us deliver our services. By using our services, you agree to our use of cookies.