Need help understanding how blocks of code execute

I’m helping my 9 year old daughter program with our RVR, and so need to learn more myself so I can teach her. Basic question about block programming that I can’t find online or figure out through experimentation: How should I think about different blocks of code executing, meaning should I think of them executing in parallel, or series, or something more complicated? For example, if I have a basic block of code that tells the RVR to move forward at a certain speed for 1 minute, and then I have a separate block that say “if the sensor sees this shade of red, turn right and move for 10 seconds”, how does the robot execute those? It executes the main block and the RVR moves, and if during its movement it goes over a red square, then it turns and moves for the 10 seconds. Did both blocks execute in parallel and then the sensor input acts as an interrupt to the first block of code? Does how I spatially lay these two blocks out on the screen matter (e.g. top to bottom, or left to right?). This is just an example but would appreciate any help on how to think about various blocks executing in relationship to each other. Thanks, Andy!

Hey aforssell!
Even I had such questions when I first started with block coding on RVR. So, the thing is the colour sensor will always work in parallel with your main code. You must have noticed that the sensor block doesn’t get attached to the main program itself. So, once you place it on your screen and execute the code, it’ll keep running in the background along with your main code. Also, where you place it on the screen doesn’t matter. It’ll still be considered a part of the program.
One more thing, try to match the shapes among the different options available. That way, you’ll know what’s compatible where.
Hope this helps,
apflash

1 Like

Thanks very much! To make sure I understand, though, one follow-up: Imagine to have a main block of code that goes through a long sequence of actions to move the robot around, and during one part of that movement you wanted it to perform Action A when it passed over a red square, but during a later part of that movement, you wanted it to perform Action B when it passed over a red square. Is it really not possible to embed color sensor code in the main block so that it runs at a certain point in a sequence? It hast to run in parallel? And if so, to do what I describe, would you have to put a conditional in the color sensor code to key off a variable or something so that it could direct a different action depending on which phase of movement the robot is in now?

1 Like

Yes, that’s exactly right. You’ll need to put a conditional to execute different codes everytime the colour sensor picks up red. As you mentioned, you can do it using variables and creating functions. Unfortunately, there is no way of integrating the colour sensor block to the main program.
Hope this helps,
apflash

1 Like