Difference between revisions of "Showing the Time in A.M. and P.M."
imported>Vswe (New Page) |
imported>Darkness X |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{Tools|req0=[[The Elder Scrolls Construction Set|Construction Set]]}} | |||
If you use GameHour it prints out 4.5 if the time is 4:30 A.M and if the time is P.M. it prints out 16.5. But with the right script we can make the GameHour print out 4.30 P.M. if the time IS 4:30 P.M. | If you use GameHour it prints out 4.5 if the time is 4:30 A.M and if the time is P.M. it prints out 16.5. But with the right script we can make the GameHour print out 4.30 P.M. if the time IS 4:30 P.M. | ||
First of all we need | |||
First of all we need some variables: | |||
float time | float time | ||
short hour | |||
Then check the time: | Then check the time: | ||
Line 10: | Line 14: | ||
set time to GameHour | set time to GameHour | ||
Now we need to | Now we need to isolate the hour from the minutes. | ||
Assigning a float value to a short var truncates the decimals and that is what we need here (so 4.5 becomes 4, 13.93 becomes 13, etc): | |||
set Hour to time | |||
Then, to check the minute just subtract the Hour from the GameHour, like this: | Then, to check the minute just subtract the Hour from the GameHour, like this: | ||
Line 38: | Line 31: | ||
message "%.2f P.M. " time | message "%.2f P.M. " time | ||
Endif | Endif | ||
This part just check if the time is less | This part just check if the time is less than 12, if it is call it A.M., Else call it P.M. | ||
But it won't work perfectly yet, we need to subtract 12 from the time if it's P.M. (If the time is showing 16.30 we subtract it with 12 and ad P.M. = 4.30 P.M.) | But it won't work perfectly yet, we need to subtract 12 from the time if it's P.M. (If the time is showing 16.30 we subtract it with 12 and ad P.M. = 4.30 P.M.) | ||
Line 70: | Line 63: | ||
Scn ClockwithAMandPM | Scn ClockwithAMandPM | ||
float time | |||
short Hour | |||
begin onActivate | |||
set time to GameHour | set time to GameHour | ||
set Hour to time | |||
set time to time - Hour | set time to time - Hour | ||
set time to ((time / 5) * 3) | set time to ((time / 5) * 3) | ||
set time to time + Hour | set time to time + Hour | ||
if time < 12 | |||
if time < 1 | |||
set time to time + 12 | |||
endif | |||
message "The Current time is %.2f A.M. " time | |||
elseif time < 24 | |||
if time >= 13 | |||
set time to time - 12 | |||
endif | |||
message "The Current time is %.2f P.M. " time | |||
endif | |||
end | end | ||
[[Category: Useful Code]] | |||
[[Category: Tutorials]] | |||
[[Category:Scripting Tutorials]] |
Latest revision as of 09:58, 15 April 2010
Tools used in this tutorial
Required |
If you use GameHour it prints out 4.5 if the time is 4:30 A.M and if the time is P.M. it prints out 16.5. But with the right script we can make the GameHour print out 4.30 P.M. if the time IS 4:30 P.M.
First of all we need some variables:
float time short hour
Then check the time:
set time to GameHour
Now we need to isolate the hour from the minutes. Assigning a float value to a short var truncates the decimals and that is what we need here (so 4.5 becomes 4, 13.93 becomes 13, etc):
set Hour to time
Then, to check the minute just subtract the Hour from the GameHour, like this:
set time to time - Hour
Now we have the minutes in decimals but we need to translate it to minutes. To that we use this:
set time to ((time / 5) * 3)
Now when the minutes are correct we can add the hours again:
set time to time + Hour
Now we have the right time but we still want to make 4:30 P.M. showing 4.30 P.M not 16.30.
If time < 12 message "%.2f A.M. " time Elseif time < 24 message "%.2f P.M. " time Endif
This part just check if the time is less than 12, if it is call it A.M., Else call it P.M. But it won't work perfectly yet, we need to subtract 12 from the time if it's P.M. (If the time is showing 16.30 we subtract it with 12 and ad P.M. = 4.30 P.M.)
Change it like this:
If time < 12 message "%.2f A.M. " time Elseif time < 24 if time >= 13 ;we still want 12P.M. to be 12 P.M. not 0 P.M. set time to time - 12 endif message "%.2f P.M. " time Endif
Now we just need to do one more thing. As it is now 12 A.M. gives the output 0 and showing 0 A.M.
We need to correct this part once more:
If time < 12 if time < 1 ;Only when the time is something with 12 A.M. set time to time + 12 endif message "%.2f A.M. " time Elseif time < 24 if time >= 13 ;we still want 12P.M. to be 12 P.M. not 0 P.M. set time to time - 12 endif message "%.2f P.M. " time Endif
The whole script can look like this
Scn ClockwithAMandPM float time short Hour begin onActivate set time to GameHour set Hour to time set time to time - Hour set time to ((time / 5) * 3) set time to time + Hour if time < 12 if time < 1 set time to time + 12 endif message "The Current time is %.2f A.M. " time elseif time < 24 if time >= 13 set time to time - 12 endif message "The Current time is %.2f P.M. " time endif end