Not being able to set the start value in blocks is kinda annoying, I will admit…
Though I will say, I agree that technically I can’t implement full For loop use in blocks, as the initialization, incrimination, and main body can all technically have any code you want in them. The check area can just be a Boolean input though, which works fine. And yeah, technically people could just use a While loop, but what’s the fun in that?!?
I like teaching students how to express a counter-driven for() loop as a while() loop to show an example of how a while() loop is supposed to be written:
- Determine your control variable.
- Initialize the control variable before entering the loop.
- Use the control variable in the conditional expression.
- Alter the value of the control variable within the loop.
I have added a block that people can use to make their own fonts, without having to paste them into the javaScript. THIS DOES NOT WORK WITH FANCY TEXT FONTS! It is meant to make my Makecode Font Editor easier to use for block users.
@AlexK I forgot about this, but I’ll look into the For loop. I don’t know how I will be able to increment the variable the user provides like the actual For block can do. I’ll need to find the code for that block and copy it.
I know this isn’t arcade, but could you make an extension that adds metadata blocks to the Makecode for Microbit editor?
What exactly do you mean by metadata?
Like, changing the name of a variable by a variable. kind like this:
(the first bubble is the name, and you are able to put another variable into it to actively change it.)
I suppose I could make something like that. What exactly do you need it for? I mean, at a certain point you must realize that blocks have limits that JavaScript simply doesn’t have and at least try to learn it instead of creating a new extension for it…
Uhh anyways, yeah, what is the use for this exactly? (I can almost guarantee that you can achieve this effect using arrays instead…)
@richard
1)
I found a bug with the expandable block variable inputs. Before you expand a block using the “+”, there is a drop point in the top left corner of the block (obviously [0, 0] relative to the block because the drop point has not yet been fully defined) where you can drop in variables, which appear again when you expand the block:
2)
I found this bug while trying to implement a For loop with a minimum and step inputs. I’m wondering if it’s possible to replicate the normal block For loop, with the ability to drop your own variables into that “index” area and have them work correctly.
My current code:
Ok I figured out that the actual For block in makecode is essentially coded as its own thing an is not built using normal block syntax, which is unfortunate. Same with the IF block. So I won’t really be able to make that functionality unless Richard has some secret knowledge to share with me.
This seems to work:
//% block="for $index from $start to $stop skip $inc"
//% handlerStatement
//% start.defl=1 stop.defl=10 inc.defl=1
//% draggableParameters="reporter"
//% hidden
export function test(
start: number,
stop: number,
inc: number,
body: (index: number) => void
) {
for (
let counter: number = start;
counter <= stop;
counter += inc
) {
body(counter)
}
}
Feel free to shine it up however you like.
The functionality I was trying to recreate was this ability of the For loop to change the variable inside:
Otherwise, my code does the same thing yours does. I just wanted it to be perfect, though it seems that is not possible, so I’ll push my current code to gitHub now!
I am curious what that “//% hidden” does. I didn’t see anything change when I removed it.
@richard I’ve been encountering a few issues with the project list on the home page not showing the projects it should.
This is my home screen:
But this is the actual list of projects when I click on “View All”:
That “Asteroids and Laser Beams” project is the 9th project in that list, but is the 3rd project on my home screen (sorry for bad screenshots that don’t really show what I’m talking about)
Also, two of those “pxt-javascript-extras” projects are actually named “pxt-javascript-extras - Copy” when I open them. I did find it interesting that those copies also let me push to the same gitHub repo, which is neat.
Ah. Yeah … changing the control value inside of a for() loop is … not recommended.
Although, you’re right… You can manipulate the control variable in Blocks. Interesting. I wonder if TypeScript likes variables by reference. ![]()
//% hidden prevents the code snippet from appearing in the toolbox when switching to a typing language. TypeScript and Python have their own ways to handle for() loops; no need to clutter the toolbox with redundant snippets.
Ah, I suppose literally every block in my extension should be hidden then, but also if you were using javaScript you wouldn’t need my extension at all. I’ll do that to them all when I have the time I suppose.
@AlexK approves posts so fast that I could actually do an “Edit: thanks for the like, @AlexK” thing every time if I were a more annoying person.
@richard another bug just now. I was editing the Json file because I was checking to make sure I had added the “shader”: “*” line to it. When I switched back to the extension file, this happened:
Then I went to restore it using the history and pressing the restore button just did nothing the first time, then it worked the second time but I got the classic “project had a conflict, changes stored in “… - Copy” screen. Going back to the projects list screen and neither copy has the " - Copy” title:
When I open that first one, it has the " - Copy"
And still only one of them shows up in the normal projects view:
Obviously I could always just restore from the GitHub version if something when terribly wrong, so I’m not super worried. I’m once again bug reporting here because I’m too lazy to make a proper report on GitHub.
Ok, I’ve added the new shader implementation to the extension. By the time this is approved, I should have a new release created! Here is an example project for the new shader blocks:
Will I be explaining how these work in the future? Ehhhhhh… probably…? I’m thinking of making some tutorial/explainer type posts in the future, so probably. In the meantime, if someone asks directly, I will most certainly explain!
As usual, if you have any issues at all, let me know!
@Richard I’ve been having many “project was edited in multiple places and the changes conflict!” pop ups while using this extension in blocks. Could there be an issue with my function → block conversion code or maybe with super large extensions? Idk. It could just be crappy school internet.
oooh fun new update
Will the update break all the old blocks?
I don’t think the update should break anything but I didn’t have time to test that! (I don’t have any old projects that use it to test on, so I’ll have to use someone’s forum game)
That’s the main thing I haven’t tested yet. If you have an old project, make a copy, update it in the copy and if anything goes wrong please let me know!














