0 votes
by (140 points)

So I have time set like this

(print: $timeH):(print: $timeM)

So i can change time in Minutes and Hours depending on the length of the event and 


then if 60 minutes pass I was going to do somthing like this:

(if: $timeM is 60)[(Set: $timeH to +1)]
(if: $timeM is 60)[(Set: $timeM to 00)]

But, A: when it add 1 to 10 it just outs 1 and displays 00 as 0


any ideas on how to better do this? I'm using Halowe


1 Answer

0 votes
by (159k points)

when it add 1 to 10

As explained within the details section of the (set:) macro, the correct syntax to modify the current value of a variable is.

(set: $timeH to it + 1)

and displays 00 as 0

You are using the $timeM variable to store the number of minutes (an integer in this use-case) and 00 isn't a valid number (or integer) in maths, so it is being shorten to 0 (zero) which is a valid number (and integer). This is why the value of $timeM is displayed the way it is.

if 60 minutes pass I was going to do something like this

Both of those (set:) macros could be issues within the same (if:) macro associated hook.

(if: $timeM is 60)[\
	(set: $timeH to it + 1)\
	(set: $timeM to 0)\


You can use code like the following to left zero pad a number to a set number of digits, it uses the (text:) macro to convert the number in the $number variable into a String and it uses the (range:) macro with negative number as parameters to access the character at the end of the String.

(set: $number to 9)

zero pad to 2 digits: (print: ("0" + (text: $number))'s (range: -2,-1))

zero pad to 3 digits: (print: ("00" + (text: $number))'s (range: -3,-1))

zero pad to 4 digits: (print: ("000" + (text: $number))'s (range: -4,-1))

... you will notice that the pattern in the above is:
a. That the number of zeros in the String value ("0") being append to the start of the the String representation of $number variable is one less than the number of digits you want in the final output.

b.  That the first parameter of the (range:) macro is the negative of the number of digits you want in the final output.

An example based on your original example would like something like.

(set: $timeM to 9)

minutes: (print: ("0" + (text: $timeM))'s (range: -2,-1))

(set: $timeM to 21)

minutes: (print: ("0" + (text: $timeM))'s (range: -2,-1))