Discuss Scratch

CDBrian
Scratcher
4 posts

Drawing using 'mouse down?'

My browser / operating system: MacOS Macintosh X 10.14.6, Chrome 89.0.4389.128, No Flash version detected

I work with children as part of a CoderDojo group. I recently created a ‘line follower’ program, but at the moment I have to draw a path for it on a backdrop. I want the kids to be able to draw a free-hand path that the ‘robot’ can follow. I set up a ‘forever’ loop as follows:

forever
if <mouse down?> then
go to [mouse-pointer]
pen down
else
pen up

end

but all that happens is that the pen leaves a single dot in the selected colour whenever I click the left button.
Where it really starts to get weird though is that I've used exactly the same combination of blocks before, and when I import them from a previous project, they work! A few years ago, in Scratch 1.4, I created a simple ‘paint’ program, where users can draw with the mouse and select the colour and size of their ‘brush’, using this exact mechanism. I found the old project and opened it in the current version of Scratch - it worked perfectly so I exported the sprite and imported it to my line follower script. Again, it worked perfectly, but when I re-entered the same blocks from the Scratch 3.x palette, the routine failed to work as expected. Obviously I can ‘magically’ fix my own script but I can't share this drawing routine with the members of the group if it's going to defy logic. Interestingly, if I change the first block to:
if <not <mouse down?>> then

end
that works as you would expect - the sprite draws a continuous line as it moves around, as long as the mouse button is NOT pressed.

I've never used this forum before so apologies if I'm breaking any conventions - I did search for this problem in the forum before posting but couldn't find anything. Any light that anyone can shed on this would be appreciated.
Thanks!
Surris
Scratcher
12 posts

Drawing using 'mouse down?'

Hello !
I tried your first script, and it works, but only when you do it in fullscreen. Did you try this ?
Sorry if they are some errors, I don't speak Englisch…

“Aimer, ce n'est pas se regarder l'un dans l'autre, c'est regarder ensemble dans la même direction.”

Saint-Exupéry
scienceexplorer1
Scratcher
100+ posts

Drawing using 'mouse down?'

If you are in editor mode then you might “drag” the sprite
Scratch does this so it can be easier to move sprites.

If you don't want the sprites to drag view it in fullscreen.


Hope this helps!

Be cool
- Chilout -
https://www.youtube.com/watch?v=4uoXbsmEBf4


The future lies ahead of us.

Did you know the universe is immensely filled with vacuum rather then any form of matter inside of it?. Well probably you do …
But here is the thing when andromeda galaxy collides with milky way it is expected that not a single star will collide. Space is space. Matter is in a very very small space.






CDBrian
Scratcher
4 posts

Drawing using 'mouse down?'

Surris wrote:

Hello !
I tried your first script, and it works, but only when you do it in fullscreen. Did you try this ?
Sorry if they are some errors, I don't speak Englisch…

@Surris - thank you! I had not thought to try it in fullscreen mode. It's still strange that it doesn't work otherwise but your suggestion will allow us to move forward - and your English is fine

@scienceexplorer1 - thanks, but I've tried dragging it while in edit mode, and have tried adding a ‘set drag mode <draggable>’ block but it makes no difference.

I'd still love to know why a sprite with this routine attached from Scratch 1.4 works perfectly, even in edit mode. I guess there's some difference in the sprite format between the versions that causes this even though the blocks look exactly the same. It's not keeping me awake at night though

Thanks again for the input and suggestions!
Fryman2599
Scratcher
100+ posts

Drawing using 'mouse down?'

did you make the costume empty?


CDBrian
Scratcher
4 posts

Drawing using 'mouse down?'

No, should I have?
PolyBit
Scratcher
49 posts

Drawing using 'mouse down?'

CDBrian wrote:

No, should I have?
Then it's likely that you're just dragging the sprite. When a sprite is being dragged it elevates slightly creating a shadow beneath it. If you hide your sprite you should no longer be able to pick it up.

define run for (num) seconds or until <bool::#de30f2>

Please check out my post about live function values
CDBrian
Scratcher
4 posts

Drawing using 'mouse down?'

Okay, I think I need to clarify somethings. The sprite follows the pointer but puts the pen down when the mouse button is clicked. When I run the project in full-screen mode in Scratch 3.x it behaves as I want it to, in that it draws a line/leaves a trail while the mouse button is held down. When I run it in the edit view, it just draws one dot every time I click the button - it disregards the long press on the button. But this only happens when I program the sprite directly in Scratch 3.

When I import a Sprite into Scratch 3 from Scratch 1.4, which has been programmed using exactly the same blocks (albeit a few years ago), it works as I want it to in both modes. So the code LOOKS exactly the same whether it's been imported or created, but behaves differently. It's weird but I don't think it's an empty/hidden sprite issue.
D-ScratchNinja
Scratcher
1000+ posts

Drawing using 'mouse down?'

CDBrian wrote:

Okay, I think I need to clarify somethings. The sprite follows the pointer but puts the pen down when the mouse button is clicked. When I run the project in full-screen mode in Scratch 3.x it behaves as I want it to, in that it draws a line/leaves a trail while the mouse button is held down. When I run it in the edit view, it just draws one dot every time I click the button - it disregards the long press on the button.
Aha – that's the key part. In the editor you can always drag sprites. That's intentional because the editor is where you create your projects, but it also interrupts the sprite's code while you're dragging it. There's no bugs in your code or Scratch that are causing this, that's just how the editor works.

This won't be a problem for other users anyway because mainly when people view your project, they'll play it on the project page, which does not enable sprite dragging in this way, unless you set the drag mode to draggable.

D-ScratchNinja • he/him
- The following is my signature, which always shows up below my posts. -


New! Filter through my projects with my website.

Need to fix an issue? Check out this studio for solutions to some common problems!

OS: Windows 11 / Browser: Microsoft Edge / Time zone: PST/PDT
scienceexplorer1
Scratcher
100+ posts

Drawing using 'mouse down?'

CDBrian wrote:

ragging it while in edit mode, and have tried adding a ‘set drag mode <draggable>’ block but it makes no difference.

Try to use full screen, this error only happens in error intentional like what @D-ScratchNinja said.

This is due to the fact that people might want to move stuff to areas they want, use fullscreen or the project page to make a actual run.
In editor mode I assume the editor is always in draggable mode even when its turned off.

The pen is being dragged which is interrupting its performance. When you use
<not <mouse down?>>
When you do actual click your cursor is still so the pen doesn't move that's why it works.

Be cool
- Chilout -
https://www.youtube.com/watch?v=4uoXbsmEBf4


The future lies ahead of us.

Did you know the universe is immensely filled with vacuum rather then any form of matter inside of it?. Well probably you do …
But here is the thing when andromeda galaxy collides with milky way it is expected that not a single star will collide. Space is space. Matter is in a very very small space.






Powered by DjangoBB