Can't IF Compare a Variable to a Variable?

Microsoft's MakeCode platform for easy blocks-style programming

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
mnopneal
 
Posts: 13
Joined: Tue Apr 13, 2021 11:53 am

Can't IF Compare a Variable to a Variable?

Post by mnopneal »

Working with the Buckaroo plant water device bolted to Micro:bit.

I really wanted to make the Threshold a variable, which was adjusted up/down with A/B buttons.

BUT, the IF statement appears to only support comparing a variable to a fixed number. Not another variable.

And I can't seem to find how to set a variable = another variable - still another variable.

What AM I missing?

regards,

Neal

User avatar
dastels
 
Posts: 15608
Joined: Tue Oct 20, 2015 3:22 pm

Re: Can't IF Compare a Variable to a Variable?

Post by dastels »

Any two things can be compared as long as they are similar enough types.

Can you post your code, it sounds like something is a little off.

Dave

User avatar
mnopneal
 
Posts: 13
Joined: Tue Apr 13, 2021 11:53 am

Re: Can't IF Compare a Variable to a Variable?

Post by mnopneal »

Thanks for the reply. It looks like if the IF block already compares "Reading" < 950, then you can't just type in another variable name instead.

Rather you have to pick the variable, and then drag it.

User avatar
dastels
 
Posts: 15608
Joined: Tue Oct 20, 2015 3:22 pm

Re: Can't IF Compare a Variable to a Variable?

Post by dastels »

AH Makecode.. missed that. You should be able to drag the desired variable to replace the constant.

Dave

User avatar
johnpark
 
Posts: 985
Joined: Wed Mar 25, 2009 2:15 pm

Re: Can't IF Compare a Variable to a Variable?

Post by johnpark »

yes, you can drag the variables from the VARIABLES category into the comparison block. https://makecode.com/_8gbADXa0uAXt

Locked
Please be positive and constructive with your questions and comments.

Return to “MakeCode”