@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.
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.
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.
the most annoying thing i’ve tried to code is defo procedural generation, especially my Random Map Event Generation just because how complicated it was to
randomly generate something with enough variation to be unique yet consistency so it’s actually playable
store that data with nested arrays (store map data)
track player position on the map as an array
draw the map and player location data to a sprite that works the same way each time it’s opened
and in blocks
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
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.
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.)
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!
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!