Discuss Scratch

MCAnimator3D
Scratcher
500+ posts

Custom Boolean Values not Working?

I have a script that detects a ton of colors in a “move” custom block

move with sensing<<<<<<touching color [#f0f]?> or <touching color [#f0f]?>> or <touching color [#f0f]?>> or <touching color [#f0f]?>> or <touching color [#f0f]?>> or <touching color [#f0f]?>> // category=custom

but with various colors. The problem is, when I put it into my define script like this:
define move with sensing: <touching ground?>
if <touching ground? ::custom>
...
it doesn't work!

Last edited by MCAnimator3D (Jan. 26, 2014 13:53:25)

ssss
Scratcher
500+ posts

Custom Boolean Values not Working?

<touching ground ::custom>
To make it purple add ::custom to it eg. <touching ground ::custom>

And wait, are you putting the custom block in the define block? That doesn't sound right. Could you perhaps share a project with the code for me to look at ?
MCAnimator3D
Scratcher
500+ posts

Custom Boolean Values not Working?

ssss wrote:

<touching ground ::custom>
To make it purple add ::custom to it eg. <touching ground ::custom>

And wait, are you putting the custom block in the define block? That doesn't sound right. Could you perhaps share a project with the code for me to look at ?
I'll share a version of it that works the same. (The original is a surprise!) Just give me a few minutes.
MCAnimator3D
Scratcher
500+ posts

Custom Boolean Values not Working?

ssss wrote:

Could you perhaps share a project with the code for me to look at?
Here you go.
scimonster
Scratcher
1000+ posts

Custom Boolean Values not Working?

I think i see the problem. Chances are, you want the Boolean to be “unevaluated”. What happens is, Scratch evaluates the Boolean, and then passes that value to the procedure. What you probably want is Scratch NOT to evaluate the Boolean, rather like in the repeat until <> block.

Scratch does not have this capability, but a program called Snap!, based on Scratch, does. You can convert a Scratch project into a Snap! project, but not the other way around. Just be forewarned before deciding to switch languages.
DadOfMrLog
Scratcher
1000+ posts

Custom Boolean Values not Working?

MCAnimator3D wrote:

ssss wrote:

Could you perhaps share a project with the code for me to look at?
Here you go.
This is a common misconception in how custom blocks ‘get’ their values.
The basic point is that the values are fixed at the point that the custom block is run - like a ‘snapshot’ - as described above by scimonster. Once the custom block is running, its values will not change (until the next time it starts running again).

For more detailed (attempts at) explanations, read through these posts:
http://scratch.mit.edu/discuss/topic/19175/
http://scratch.mit.edu/discuss/topic/9102/
http://scratch.mit.edu/discuss/topic/22942/

Hope that makes sense!

EDIT: It's interesting that a number of Scratchers clearly ‘expect’ this behaviour for boolean reporters - i.e. they think of it as sending the actual question “touching black?” to the custom block, rather than the snapshot value for the question at the time that the block starts running. I haven't seen anyone suggesting it for any other reporters, though, (like size, or x position). so I'm curious if those expecting the booleans to work like this would also expect such reporters to work in that way, too…?

Last edited by DadOfMrLog (Jan. 26, 2014 21:59:57)

blob8108
Scratcher
1000+ posts

Custom Boolean Values not Working?

Maybe it's because we have number and string literals, but no boolean literals. It's hard to visualise a true/false value when you can't actually input it directly.
blob8108
Scratcher
1000+ posts

Custom Boolean Values not Working?

ssss wrote:

<touching ground ::custom>
To make it purple add ::custom to it eg. <touching ground ::custom>
Whoops, I'd forgotten about custom boolean parameters. I'll fix that…

Powered by DjangoBB