It is currently April 18th, 2024, 6:18 pm

Binary conversion

Get help with creating, editing & fixing problems with skins
User avatar
Codger
Posts: 97
Joined: May 29th, 2017, 3:16 pm

Binary conversion

Post by Codger »

Just amusing myself trying to figure a few routines that would be trivial in a language with conditional looping but...

Anyway, I settled on a binary clock. I started with completely brute forcing it with a million routines.
Then went for the subtler approach.

I didn't expect this coming code to work. I figured all conditionals would probably fire simultaneously. But I had to try.
I still don't know the answer to that because to my thinking this routine should have to return a 6 digit number even if it is the wrong one. Can someone explain why it is acting as it does?

Thanks.

Code: Select all

[Rainmeter]

[Variables]
ChronoInput=0
Output=""

[Binary]
Measure=String
IfCondition=(#ChronoInput#>=32)
IfTrueAction=[!SetVariable Output "1"][!SetVariable ChronoInput (#ChronoInput#-32)]
IfFalseAction=[!SetVariable Output "0"]
;
IfCondition2=(#ChronoInput#>=16)
IfTrueAction2=[!SetVariable Output "#Output#1"][!SetVariable ChronoInput (#ChronoInput#-16)]
IfFalseAction2=[!SetVariable Output "#Output#0"]
;
IfCondition3=(#ChronoInput#>=8)
IfTrueAction3=[!SetVariable Output "#Output#1"][!SetVariable ChronoInput (#ChronoInput#-8)]
IfFalseAction3=[!SetVariable Output "#Output#0"]
;
IfCondition4=(#ChronoInput#>=4)
IfTrueAction4=[!SetVariable Output "#Output#1"][!SetVariable ChronoInput (#ChronoInput#-4)]
IfFalseAction4=[!SetVariable Output "#Output#0"]
;
IfCondition5=(#ChronoInput#>=2)
IfTrueAction5=[!SetVariable Output "#Output#1"][!SetVariable ChronoInput (#ChronoInput#-2)]
IfFalseAction5=[!SetVariable Output "#Output#0"]
;
IfCondition6=(#ChronoInput#=1)
IfTrueAction6=[!SetVariable Output "#Output#1"]
IfFalseAction6=[!SetVariable Output "#Output#0"]
IfConditionMode=1
;
String=#Output#
;●○
DynamicVariables=1
UpdateDivider=-1

[MeterMinutes]
Meter=String
MeasureName=Binary
FontName=Arial
FontSize=16
FontColor=0,0,0,255
X=16
Y=16
Text=%1
UpdateDivider=-1

[MeasureMinute]
Measure=Time
Format=%#M
OnChangeAction=[!SetVariable ChronoInput [MeasureMinute:]][!UpdateMeasure Binary][!UpdateMeter MeterMinutes]

[MeasureSecond]
Measure=Time
Format=%#S
[hr][/hr][hr][/hr]
"If you are the smartest one in the room, you are in the wrong room."
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Binary conversion

Post by balala »

Codger wrote:I didn't expect this coming code to work. I figured all conditionals would probably fire simultaneously. But I had to try.
I still don't know the answer to that because to my thinking this routine should have to return a 6 digit number even if it is the wrong one. Can someone explain why it is acting as it does?
First sorry for the late reply...

I'm not sure why have you supposed on each update 6 characters will be added, if you
Codger wrote:figured all conditionals would probably fire simultaneously.
So, I think, as always, your code behaves exactly as it should: each time the number of minutes changes, the OnChangeAction option of the [MeasureMinute] measure updates the [Binary] measure. Although it's weird to put IfConditions on a string measure, I think this time they are working, because their conditions are not bound to the String measure itself. Depending on the current value of the ChronoInput variable, on each update of the measure (as I said, this happens on each change of the number of minutes) from each IfCondition either the IfTrueAction, either the IfFalseAction is executed. But on each update are executed 6 such actions, one from each group. Most of them should add a 0 after the current value of the Output variable. But these bangs being executed simultaneously (they are so!) you see just the consequence of the last one, not the consequence of each of them. Most times, this means to add a 0 after the previously existent value of the Output variable, increasing its size by one character (usually 0) on each update of the [Binary] measure.