0

unable to use console log with a Boolean variable
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

unable to use console log with a Boolean variable

by adavid7 on Mon Jan 18, 2021 7:35 pm

It seems that one cannot use console log with a Boolean variable.

From the error message in the blocks editor (screenshot below), it appears that a Boolean variable can be created by setting the variable to true or false initially. But the console log block with a value will not accept that as a parameter even though the variable declaration appears legal:

Code: Select all | TOGGLE FULL SIZE
let aBoolean = true
forever(function () {
    console.logValue("aBoolean", aBoolean)
})

I tried this is the beta version of the editor also and it still fails.

Does anyone have any advice? This seems like a bug; wondering where to report that if it is?

Code shared here: https://makecode.com/_UrTR0DKk91Xm

boolah-boolah.png
boolah-boolah.png (43.41 KiB) Viewed 231 times

adavid7
 
Posts: 68
Joined: Fri Jul 04, 2014 7:32 pm

Re: unable to use console log with a Boolean variable

by nickine9 on Tue Jan 19, 2021 7:01 am

I think you can convert boolean to text (if you have a new/spare text variable)

let ttt = ""
let bool = false
basic.forever(function () {
ttt = convertToText(bool)
basic.showString(ttt)
})

nickine9
 
Posts: 147
Joined: Fri Jan 06, 2017 4:14 am

Re: unable to use console log with a Boolean variable

by adavid7 on Tue Jan 19, 2021 12:19 pm

Right, thanks -- that's a good idea but .. ugh.

I could also just use a numeric variable with one or zero for true or false.

But I'm looking for readability in code as I teach novices.

adavid7
 
Posts: 68
Joined: Fri Jul 04, 2014 7:32 pm

Please be positive and constructive with your questions and comments.