Welcome… to
FUNCTION IMPOSTERS!
What is all this about?
Well it centers around the function category
What I want YOU to do is to create functions that mimic the blocks that you’re trying to replicate
There’s only 2 rules:
- You cannot use the block your trying to replicate in your function.
- No outside code: Everything related to the function is inside the function definition, NOTHING OUTSIDE OF IT.
For example, here’s my flawed attempt at replicating the
controller.moveSprite(sprite, vx, vy)
block:
(The red one uses the function, the blue one uses the actual block.)
So yeah
Also you can use extensions
GET TO CODING!!!
10 Likes
I hate myself for doing this but…
2 Likes
This is neat! I’ll release all my solutions but everyone should try their hand at this before looking at other peoples’ solutions!
(I’ll use blocks too, just to keep things fair… ish…)
2 Likes
Okay so I know you probably didn’t mean it like this, but it really sounds like (because of the nothing outside of the function rule), that I wouln’t be allowed to call it, because you said ANYTHING related to the function. Lol
this sounds like a lot of fun
Here is background image and background color! Color is a little scuffed because it takes in a number but it should be fine.
1 Like
Oof
Should of specified that the call block is the exclusion to all that
2 Likes
This is a very original idea! Love it!
I’m gonna get to work on it. I’ll have to think of what block to do tho.
2 Likes
So, I wanted to make it so that you could add more than one sprite, and I’ve encountered many issues while doing that! Using blocks once you’ve used javaScript is frustrating sometimes, because sometimes it does things behind the scenes that I would do very, very differently.
This is more of a giant explanation for how I did this, so it’s a very, very long post. I like doing this more than just sending a solution because I think it’s more interesting, and more fun! For me at least. I don’t know if anyone else is gonna have fun reading all this!
Spoilers!
My first “solution” used On Game Update but otherwise works about as well as it could possibly work (I’ll get to that later)
This was a bit more complicated before I cheated and looked at the actual source code for the follow block. I was doing the button checks and then moving the sprites inside the button IF blocks, instead of holding the button state inside variables and then using it later, which is much cleaner.
Then only after I had looked at the actual implementation did I realize that technically I shouldn’t be using the On Game Update block (even though that’s basically how the actual code works) so I just changed it to make it look better.
Then I tried to turn it into a single function like this, to stop using the On Game Update block:
(The “Run In Parallel” block is from my JavaScript Extras extension but it’s the exact same code as the “Separately Do” block from the timers extension)
But it turns out that since I’m not using them anywhere else, those arrays have become local variables instead of global variables, which means every time you run the function they are created new, so I changed the code to this:
Which still doesn’t work because the “isMoving” variable is still global.
My main struggles here were due to the way Makecode does global and local variables. Most variables are global but for some reason arrays are not global, which is truly annoying to me. I mean, I know that it wouldn’t be an issue if I could just add this code:
But I cannot, so I made the isMoving state variable into an array in the hopes that it would become a local variable like the other ones, but it… didn’t? Yeah. It became a global variable instead. Looking at the javaScript, I could see that for some reason this one is defined outside of the function, making it global, instead of inside the function, like the sprite arrays. This led me to realize that, for some reason, if I define a sprite array normally inside the function it becomes global!

But for whatever reason simply adding to an array inside the function without ever defining it, like I was doing before, leads to it being a local variable. So now, finally, I can actually do this whole thing inside a single function by tricking Makecode into making my sprite arrays global! I also got tired of the Run In Parallel + While loop thing, so I added an inline On Game Update block to my JavaScript extras extension just because I can. This turned out to be a really cool small adventure! Here’s my final solution:
https://arcade.makecode.com/S72282-30700-01822-40073
The smiley faces are controlled by the original block, and the boxes around them are controlled by my function!
The reason none of our functions could ever be perfect is because Makecode is a big meanie and the move sprite code is handled right before the sprite physics is done, then all our code is run after that. This means that the move sprite block will always literally be one step ahead of our code:
How unfair!
I created pong using mostly just one function
and I spelled “using wrong”
2 Likes
How did my enemy lose he’s literally always level with the ball. Good game tho. AI is simple but works.
1 Like
If you press A there are different difficulties