0

Can't IF Compare a Variable to a Variable?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Can't IF Compare a Variable to a Variable?

by mnopneal on Sun Apr 18, 2021 4:02 pm

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

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

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

by dastels on Sun Apr 18, 2021 10:34 pm

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

dastels
 
Posts: 6456
Joined: Tue Oct 20, 2015 3:22 pm

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

by mnopneal on Mon Apr 19, 2021 3:24 pm

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.

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

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

by dastels on Mon Apr 19, 2021 4:16 pm

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

Dave

dastels
 
Posts: 6456
Joined: Tue Oct 20, 2015 3:22 pm

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

by johnpark on Thu Apr 22, 2021 6:31 pm

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

johnpark
 
Posts: 870
Joined: Wed Mar 25, 2009 2:15 pm

Please be positive and constructive with your questions and comments.