Showing the Time in A.M. and 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 som varibles:
float time float hour
Then check the time:
set time to GameHour
Now we need to check what hour it is:
If time < 1 set Hour to 0 ElseIf time < 2 set Hour to 1 ElseIf time < 3 set Hour to 2 ... ElseIf time < 23 set Hour to 22 ElseIf time < 24 set Hour to 23
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 then 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 Float Hour Begin onActivate set time to GameHour If time < 1 set Hour to 0 ElseIf time < 2 set Hour to 1 ElseIf time < 3 set Hour to 2 ElseIf time < 4 set Hour to 3 ElseIf time < 5 set Hour to 4 ElseIf time < 6 set Hour to 5 ElseIf time < 7 set Hour to 6 ElseIf time < 8 set Hour to 7 ElseIf time < 9 set Hour to 8 ElseIf time < 10 set Hour to 9 ElseIf time < 11 set Hour to 10 ElseIf time < 12 set Hour to 11 ElseIf time < 13 set Hour to 12 ElseIf time < 14 set Hour to 13 ElseIf time < 15 set Hour to 14 ElseIf time < 16 set Hour to 15 ElseIf time < 17 set Hour to 16 ElseIf time < 18 set Hour to 17 ElseIf time < 19 set Hour to 18 ElseIf time < 20 set Hour to 19 ElseIf time < 21 set Hour to 20 ElseIf time < 22 set Hour to 21 ElseIf time < 23 set Hour to 22 ElseIf time < 24 set Hour to 23 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