Post by GCN on Nov 5, 2007 19:02:32 GMT -5
Step 1: The Clock
Coding level [*----]
Open the Database window and go to Common Event. Make a new parallel process called CLOCK. Mark 'Appearance Condition Switch' on. Get a new switch called CLOCK and select it as the Condition Switch.
Insert the command 'Wait...' and input 10 x0.1 sec, so the parallel process will be run every second. Get a new variable called MINUTES. Add the command 'Change variable', choose MINUTES, choose add (+) and in set, set a number that should be added every second. Now add the command Fork 'Conditions' (aka Branch), select the variable MINUTES, then input for Set 60 and as in the drop down menu choose for above (more than, including). In the new Fork, do a change variable to MINUTES by subtracting (-) it by the set value of 60. Now do another change variable, and get a new variable called HOURS. In the Fork, add (+) 1 to HOURS.
If done correctly, every time the value MINUTES exceeds 60, 60 MINUTES will be changed into one HOURS.
Now we also want this to happen when 24 hours have passed, and another day has to pass. So within the Fork, after the two variable commands, add another Fork: choose HOURS this time, set on 24 and yet again choose for above. In the new Fork, subtract 24 from HOURS. Get another new variable, called DAY. Add 1 to the variable DAY.
You now have a simple time system. If you don't want months and years, skip the extra step.
EXTRA STEP: Add months and years
Coding level [***--]
This extra step is to add months. Some months will have 31 days, some 30 days, and february even 28 or 29 depending on the year. This step will include these anomalies.
Since February is such a weird month, let's start with that one. Create a new Fork inside the HOURS Fork, below the two variable commands. Use for the fork a new variable, MONTH, and set the fork on 2, same (aka same as 2). Also, mark 'Add else case' on. If you want, you can add a Note in the Fork that says 'February', so you can easily find it back later.
Now the fun starts. Create a new variable, YEAR. Create another variable, [c]Year Checker (the c of CLOCK, as a reminder that this variable is used by the CLOCK event). Change variable [c]Year Checker, set this variable's value to the variable YEAR. Now change variable [c]Year Checker, mod by the set value of 4.
NOTE: Mod divides the variable with the set value, and instead of the outcome, he places the rest value back in the variable. So if you mod 7 by 4 you get 3. If you mod 25 by 5 you get 0. If you mod 127 by 10 you get 7, if you mod 127 by 100 you get 27. Like that.
Set a new Fork right after the 'mod': Fork [c]Year Checker, same as 0, and mark 'add Else Case' on. This basically means: if the year can be divided by 4 do this, else do that. Indeed, a leap-year. In this Fork, insert another Fork: Fork DAY above 30. Yes, this is different from minutes and hours, for there is a day 29 and no day 0. Insert in this new fork a change variable: Change DAY, subtract 29. Add another change variable: Change MONTH, add 1. Now go to the Else Case of Fork '[c]Year Checker, same as 0'. Copy the Fork 'DAY, above 30' into this else case, and change the 30 in the fork to 29, and the 29 in the change variable to 28. That was february.
Now we're gonna do the rest of the months. Recall that from January to July, the amount of days in a month go 31-30-31 (excluding February) and then in August, right after July, they go 31-30-31 again until December. Like 31-2?-31-30-31-30-31 31-30-31-30-31. During the first 7 months, odd numbers get 31 days and even numbers 30. During the last 5 months, even numbers get 31 days and odd numbers 31. Hmm...
In the Else Case of the Fork 'MONTH, same as 2', insert another change variable command. Get a new variable, [c]Month Checker. You might've guessed it, we're gonna do the same trick as with the leap-year. Change [c]Month Checker to the same value as MONTH. Now Mod [c]Month Checker by 2. Odd number will return a 1, even numbers a 0. Make a new Fork: Fork MONTH, below 7 (that includes 7), add else case. In this Fork, make another new Fork: Fork [c]Month Checker, same as 1, add Else Case. In this fork, copy the DAY Fork you already made in February, but now change the Fork to 32 and the Change DAY subtraction to 31. In the Else Case of the Fork [c]Month Checker, Copy this DAY Fork again, but now change the Fork to 31 and the Change DAY subtraction to 30. Good, we're almost there. Now copy the whole Fork [c]Month Checker, and copy it into the Else Case of the MONTH Fork. Then swap the two DAY Forks; Fork Month Checker same as 1 should get DAY Fork 31, the Else Case should get DAY Fork 32
Now all we miss is that every 12 monts make a year. Remember, the 12th month exists as well, so a new year should be added when the 13th month starts.
Add a new Fork, right under (not in!) the Fork 'MONTH same as 2' This Fork should be: Fork MONTH, above 13. No Else Case. Inside this Fork, Change MONTH by subtracting 12, and Change YEAR by adding 1.
END OF EXTRA STEP
Coding level [*----]
Open the Database window and go to Common Event. Make a new parallel process called CLOCK. Mark 'Appearance Condition Switch' on. Get a new switch called CLOCK and select it as the Condition Switch.
Insert the command 'Wait...' and input 10 x0.1 sec, so the parallel process will be run every second. Get a new variable called MINUTES. Add the command 'Change variable', choose MINUTES, choose add (+) and in set, set a number that should be added every second. Now add the command Fork 'Conditions' (aka Branch), select the variable MINUTES, then input for Set 60 and as in the drop down menu choose for above (more than, including). In the new Fork, do a change variable to MINUTES by subtracting (-) it by the set value of 60. Now do another change variable, and get a new variable called HOURS. In the Fork, add (+) 1 to HOURS.
If done correctly, every time the value MINUTES exceeds 60, 60 MINUTES will be changed into one HOURS.
Now we also want this to happen when 24 hours have passed, and another day has to pass. So within the Fork, after the two variable commands, add another Fork: choose HOURS this time, set on 24 and yet again choose for above. In the new Fork, subtract 24 from HOURS. Get another new variable, called DAY. Add 1 to the variable DAY.
You now have a simple time system. If you don't want months and years, skip the extra step.
EXTRA STEP: Add months and years
Coding level [***--]
This extra step is to add months. Some months will have 31 days, some 30 days, and february even 28 or 29 depending on the year. This step will include these anomalies.
Since February is such a weird month, let's start with that one. Create a new Fork inside the HOURS Fork, below the two variable commands. Use for the fork a new variable, MONTH, and set the fork on 2, same (aka same as 2). Also, mark 'Add else case' on. If you want, you can add a Note in the Fork that says 'February', so you can easily find it back later.
Now the fun starts. Create a new variable, YEAR. Create another variable, [c]Year Checker (the c of CLOCK, as a reminder that this variable is used by the CLOCK event). Change variable [c]Year Checker, set this variable's value to the variable YEAR. Now change variable [c]Year Checker, mod by the set value of 4.
NOTE: Mod divides the variable with the set value, and instead of the outcome, he places the rest value back in the variable. So if you mod 7 by 4 you get 3. If you mod 25 by 5 you get 0. If you mod 127 by 10 you get 7, if you mod 127 by 100 you get 27. Like that.
Set a new Fork right after the 'mod': Fork [c]Year Checker, same as 0, and mark 'add Else Case' on. This basically means: if the year can be divided by 4 do this, else do that. Indeed, a leap-year. In this Fork, insert another Fork: Fork DAY above 30. Yes, this is different from minutes and hours, for there is a day 29 and no day 0. Insert in this new fork a change variable: Change DAY, subtract 29. Add another change variable: Change MONTH, add 1. Now go to the Else Case of Fork '[c]Year Checker, same as 0'. Copy the Fork 'DAY, above 30' into this else case, and change the 30 in the fork to 29, and the 29 in the change variable to 28. That was february.
Now we're gonna do the rest of the months. Recall that from January to July, the amount of days in a month go 31-30-31 (excluding February) and then in August, right after July, they go 31-30-31 again until December. Like 31-2?-31-30-31-30-31 31-30-31-30-31. During the first 7 months, odd numbers get 31 days and even numbers 30. During the last 5 months, even numbers get 31 days and odd numbers 31. Hmm...
In the Else Case of the Fork 'MONTH, same as 2', insert another change variable command. Get a new variable, [c]Month Checker. You might've guessed it, we're gonna do the same trick as with the leap-year. Change [c]Month Checker to the same value as MONTH. Now Mod [c]Month Checker by 2. Odd number will return a 1, even numbers a 0. Make a new Fork: Fork MONTH, below 7 (that includes 7), add else case. In this Fork, make another new Fork: Fork [c]Month Checker, same as 1, add Else Case. In this fork, copy the DAY Fork you already made in February, but now change the Fork to 32 and the Change DAY subtraction to 31. In the Else Case of the Fork [c]Month Checker, Copy this DAY Fork again, but now change the Fork to 31 and the Change DAY subtraction to 30. Good, we're almost there. Now copy the whole Fork [c]Month Checker, and copy it into the Else Case of the MONTH Fork. Then swap the two DAY Forks; Fork Month Checker same as 1 should get DAY Fork 31, the Else Case should get DAY Fork 32
Now all we miss is that every 12 monts make a year. Remember, the 12th month exists as well, so a new year should be added when the 13th month starts.
Add a new Fork, right under (not in!) the Fork 'MONTH same as 2' This Fork should be: Fork MONTH, above 13. No Else Case. Inside this Fork, Change MONTH by subtracting 12, and Change YEAR by adding 1.
END OF EXTRA STEP