🦾 Weekly Topic: Most Challenging Coding Task or Concept

@WoofWoof it is not possible to get a list of the functions/variables exported from a namespace at runtime in MakeCode.

The JavaScript language that MakeCode uses is something we like to call “Static TypeScript”. It’s based off of the TypeScript programming language but has a few restrictions/differences to make it possible for us to compile down to something that can run on extremely low-end hardware (like a micro:bit). You can find out more info on the differences between Static TypeScript and vanilla TypeScript here.

Normal TypeScript gets converted into JavaScript, which is interpreted in your browser or in a runtime like Node.js. I won’t get into how code interpretation works here, but suffice to say it requires hardware with more RAM and CPU power than devices like the micro:bit have. To get around this, we actually compile Static TypeScript from text to binary code much like how a compiler for a language like C++ would. This lets us create code that is much more efficient and can run on inexpensive hardware.

Anyways, back to your original question: in regular TypeScript, you can iterate over the exported functions/variables in a namespace like this. That’s because regular TypeScript implements namespaces as JavaScript objects, which work with Object.keys().

That same code is an error in MakeCode, because we implement namespaces differently.

9 Likes

Another common point of confusion is the difference between Java and JavaScript. Java actually has absolutely nothing to do with JavaScript! The languages are very, very, different and they are used for very different purposes.

The reason JavaScript is called JavaScript is because the creator thought it would be a good marketing move to give it a name that referenced an already popular programming language. IMO this was a terrible decision, because now everyone gets super confused whenever the two are brought up.

It’s like if I decided to make a programming language and name it C+++ just for name recognition.

10 Likes

I would 100% use c+++ if I could use it to get a list of all variables in a namespace. I suppose I would also like to declare variables in this language too, but that’s a want, not a need.

3 Likes

the most annoying thing i’ve tried to code is defo procedural generation, especially my Random Map Event Generation :world_map: just because how complicated it was to

  1. randomly generate something with enough variation to be unique yet consistency so it’s actually playable
  2. store that data with nested arrays (store map data)
  3. track player position on the map as an array
  4. draw the map and player location data to a sprite that works the same way each time it’s opened

and in blocks :melting_face:


When it comes to extensions like block objects, sprite data and mini menu, what I found useful was to look at the code of existing projects and figure out my own code using that as a template
That can be very difficult for starting right out so tutorials like this: [Tutorial] What are block objects, and how to use them are super helpful. ty @Sarge : D


Finally, scope creep, the death knoll of all my projects lol
How it usually goes is like such:

  • make some cool code
  • get inspired and massively overplan game to become unreasonably large, complex and difficult to code
  • burn out halfway and never finish the game
9 Likes

Thanks a lot for this explanation! My disappointment is quite measurable and my day is most definitely not ruined. That Java / JavaScript thing is definitely why I couldn’t find solutions online, though I suppose I would have been even more confused upon finding a working method and it not working in Makecode.

4 Likes

“C makes it easy to shoot yourself in the foot. C++ makes it harder, but it blows your whole leg off when it does.” What would C+++ do? :thinking: :crazy_face: :rofl:

8 Likes

instant death.

6 Likes

Cutscenes, music, level design, and looking at past code

7 Likes

My problems mostly stem from what little time I have to work on my games. I’m also a bit too imaginative and strive for a game that’s a lot better than what I can actually produce. (i.e, my imagination is overactive.)

8 Likes

Raycasting.

1 Like

Motivation :pensive:

4 Likes

Oof. Looking at past code hurts. I always avoid looking at it because I know it will be untraceable spaghetti. Then again, it’s a nice way to see how far I’ve come!

3 Likes

ABSOLUTE TORTURE…

Those days where you’d set a variable to false, and instead of saying “if NOT(variable)”, you say “if (variable)=false” LIKE BRO YOU HAD ONE JOB! ONE! JOB!

8 Likes

Hahaha!

@richard and @UnsignedArduino: You mean like the 4 plusses in C# and the added amplification of pain for each new plus, respectively? :wink:

1 Like

i would much rather code in C# than C++!

heck i’d rather code in C than C++ too

5 Likes