Longer scratch codes give major drag slowdown (Solved, workaround)


#1

Hi,

I think there is a bug in the mblock program. The longer my scratch code gets, the slower it is with dragging code. I’m now at a point of extreme lag when dragging code. I have an I7 with a good graphics card and loads of memory so that can’t be the problem imho.

Can I do something about this or is this a known bug?

Best regards,

Marco.


#2

I’d suggest checking with the Scratch forum. mBlock is based on the Scratch 2.0 offline editor and Makeblock only provides extensions, a code generator, and integrates with the Arduino compilation environment.

@tec_support, can you confirm?


#3

Which version of mBlock are you using?


#4

I’m using 3.4.10


#5

That might be the case. In the scratch forums many people have this problem. I don’t understand why though.


#6

I suspect its the nature of the Flash virtual machine bogging down (The editor which is currently written in Adobe Flash (which Adobe is in the process of sunsetting). A lot of the Flash developers that I am acquainted with have voiced complaints about the limitations for some time. Flash has been pushed way past the point it was originally designed for (small web games, advertisements). It’s been patched to the point that it is a creaky, non-secure mess which is likely why Adobe is throwing in the towel on it.

The Scratch team is currently working with Google to redo Scratch based on Google’s Blockly project and I suspect that you will see mBlock transitioned over sooner rather than later.


#7

Well I certainly hope so. I’m currently at the end of scratch programming. I have the code attached. Maybe it can be optimized more as I’m not an expert.

The alternative is to continue in C in the Arduino IDE…
I really hope they ditch adobe real soon. Thanks for you clear answer.

Main v17.zip (40.7 KB) - For Mbot v1.1
It’s basically the firmware in scratch with better line follower and other extra’s.

Up/Down/Left/Right= Basic controls
B= Wheelie
A= Collision avoid mode
C= Line follow mode
E= Paw Patrol tune
0= Imitate Dutch police (will be redone using timer and parallel to other code)
4= Forward and left
6= Forward and right

As soon as you load the program in mblock you will notice extreme lag while dragging things. It’s not fun anymore.


#8

Are you uploading the program for standalone operation or are you running the program through mBlock? A couple of quick suggestions as I look through the code:

  1. There is a lot of repeated code. Try isolating that into custom blocks (Make a Block from the Data&Blocks palette will create a new block and you can drag the common code under it) to reduce the total number of blocks.
  2. Do the same thing for the blocks inside the if-tests to reduce the overall length of the main loop. Currently it’s tough to read all the way through.

The Scratch parser seems to have to parse the entire set of blocks so breaking up the one big block into smaller blocks should reduce the slowness (it works for me anyway). It’s also considered best practice to use custom blocks for housing functionality to make the program easier to read and to maintain. :slight_smile:

Just my two cents. :slight_smile:


#9

Thanks for the great tips. I’m uploading it for standalone operation. Will try to clear up the code somewhat and hope for the best.

I indeed saw the seperate block thing. Works like a function or sub right? I’ll let you know after implementing if it got better.


#10

I want to thank you again. After first placing the song in a seperate block I got 50% of speed back. Will now continue to block the rest that is seperable. Thanks a million, works like a charm!


#11

No worries, I’m glad that the problem is solved (at least for now). :slight_smile: