Is it possible to use the PXT Arcade platform to write blocks or Typescript code that transpiles to C#?

I’m currently working on a game in Unity based around stories. It’s still early in development so I won’t go into details, but a big part of it is reliant on users being able to submit their own stories, including written content and details, 3D models and basic level design. I have been contemplating how to build a level editor or mini game builder for years now. There was a cool VR level editor tool provided by Unity (which could be used without VR from what I remember) but it got discontinued and was left in a bad state. Trying to update it to work with the more modern VR tools would have been an exercise in futility.

I then considered building a package for Unity that users could install and use to build out their story worlds. This would give them most of the power of Unity, but then it becomes difficult to limit scripts and other content that could cause issues or contain malware (for an example, look up the abuse of scripting in Roblox). Then I considered building an app (for desktop and maybe mobile) that would allow the user to create their story, characters items etc and do some basic level design. Unity can be used to build this sort of thing relatively easily. However, then the user’s creativity is limited. So I was a bit stuck.

A few months or so ago, I got back into Makecode Arcade and I’m loving it. I had used it before and even bought a device for it, but I lost interest quickly. I have been working as a software developer for 12 years so the limitations of the blocks annoyed me. However, when I started coding in Typescript, I fell in love with the platform. I was amazed at how flexible it is and how much you can do. I also love Typescript so that helped.

Anyway, after playing around with Makecode Arcade for a while (and digging into how PXT works and how to load custom images and tile sheets, which took some experimentation), I started wondering if I could use the underlying PXT framework as an editor for my game.

On paper, it doesn’t seem feasible. The only supported languages are Typescript and Python, arcade is intended for small hardware devices, the simulator is built to run what are essentially web games and there is no built in support for C# or even transpiling to C#. It will be a lot of work to just set up transpiling, not to mention I will have to map Typescript objects to the underlying Unity objects, which could get complex fast.

However, in order to not limit myself or the players/users, I am building the game differently from the conventional way. The “platform” that stores the data will be separate from the game. This will be stored on the cloud and accessible via an API. I am also building a C# SDK that can be used in Unity (or any other C# platform as I’m building it to be platform agnostic) to pull the data, including the assets and level layouts. I can also build SDKs in other languages to support being used in other frameworks. An API is platform agnostic by design, so it works well in this case. I’m building it this way so I can essentially create new game “clients” in a variety of different engines. I may even allow users to create their own games uding their stories from our API. The story will be the same but the gameplay could be different. This is the broad plan going forward but right now I’m just focusing on the API, the SDK and the Unity game. The story and level building tools will come later, but I want to understand the feasibility now.

If you’re wondering why I’m so keen to use PXT, it’s because I’m very passionate about education, particularly programming. I became a software developer to make a difference in the world and education is my current focus. The game is being built to encourage people to read, but I also want to encourage people to create. I really want to include some version of programming in making content for the game and I want to give users some level of freedom when building out their story levels. There are open source block libraries out there that I can use, but I really like PXT, it’s open source and it’s been made to be extended.

So very long story short, would it be possible and/or feasible to add a C# transpiler to PXT that I could use to convert Typescript and blocks to C#? I know Blazor has interop between Javascript and C# but I don’t know if I’ll be able to just pull that section of Blazor and it probably won’t work 100% for typescript.

Adding a simulator to the page to show the game is also a whole other challenge as I can’t embed the Unity engine into a browser. I’ll have to make a specific version of the game client that can take in code input from PXT.

All in all, it sounds like it will be very complicated and will probably cause me tons of headaches. I just wanted to know if it was possible and if anyone has tried it before, or could point me in the right direction.

Otherwise, I’ll just build a package for Makecode that can pull in the data from the API and allow it to be used in a game. From what I’ve seen, Makecode doesn’t support fetch (because most devices don’t have Wifi and/or don’t allow internet connections) but I can add a button to the API Website that will allow the user to get all the game data as a typescript file. I’ll need to look at how I compress the file so it doesn’t take up all the device’s memory.

1 Like