MicrosoftDocs / minecraft-creator

This is the repository for Minecraft Bedrock documentation.
Creative Commons Attribution 4.0 International
182 stars 132 forks source link

The TypeScript starter project didn't do anything #656

Open and-there-it-goes opened 1 year ago

and-there-it-goes commented 1 year ago

I was trying to follow the tutorial exactly (the second time) and I got up to near the end of Chapter 2, and everything was fine, but the script didn't output anything in Minecraft. The world was a regular world. I waited a whole minute, but nothing happened. The only possible difference was that I had turned on all the experimental toggles, rather than only the Beta APIs toggle. I added a test console log into the very start of main.ts (after the import) and I never got the log message. I also tried to connect Minecraft's debugger (/script debugger connect localhost[port number]) using the port Visual Studio Code said it was listening on, but it failed.

I also noticed that the behavior pack's manifest.json contained main.js rather than main.ts, and the language was set to javascript.

Another note: The website tutorial's code for Utilities.ts contains a TypeScript error that the getBlock() functions may return undefined, so the setPermutation() functions would cause an error. In my first attempt to roughly follow the tutorial, I fixed this by only running setPermutation() if the return value of getBlock() wasn't undefined.


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

4-3is4-me commented 1 year ago

@D2Undead Hello, I have also worked through this tutorial in the last few days. I have got it working. Firstly, main.ts is written in TypeScript, which is an extension of JavaScript. TypeScript must first be compiled to JavaScript to be run in Minecraft. This is what gulp is doing; it compiles main.ts to main.js (also Utilties.ts to Utilities.js) and copies the required files to the behaviour packs in the com.mojang folder. This is where Minecraft picks them up from, so it is right for the manifest.json to be the way it is. Are there any errors when you run gulp?

If not, then I suggest you follow these steps again, exactly:

Once in the world any errors will display and can be retrieved from settings - creator - content log. Enable the content log if you haven't already then exit and reload to begin the log. For example, in the latest update, it told me the @minecraft/server version was incorrect and gave some options, I changed the version in manifest.json to 1.4.0-beta and all was fine.

I also had the issue with Utilities.ts and solved it like this overworld?.getBlock({ x: i, y: j, z: k })?.setPermutation(perm);

Interestingly, the code in the ts-starter-complete-cotta/scripts/main.ts is completely different to the code snippets given in this tutorial. In chapter 4, I had to replace: overworld?.getBlock({ x: cottaX + ARENA_X_OFFSET, y: 1 + ARENA_Y_OFFSET, z: cottaZ + ARENA_Z_OFFSET}); overworld?.setPermutation(BlockPermutation.resolve("yellow_glazed_terracotta")); with let block = overworld .getBlock({ x: cottaX + ARENA_X_OFFSET, y: 1 + ARENA_Y_OFFSET, z: cottaZ + ARENA_Z_OFFSET }); if (block) { block.setPermutation(BlockPermutation.resolve("minecraft:yellow_glazed_terracotta"));

from the ts-complete-cotta/scripts/main.ts but otherwise the code snippets worked. I wonder if the tutorial just hasn't been updated yet.

mammerla commented 1 year ago

Sorry for the delay - yes, I've updated the project to use 1.5.0-beta which works with 1.20.20 preview. Also, as 4-3is4-me notes, you do need to add question marks. I've updated the Readme here: https://github.com/microsoft/minecraft-scripting-samples/tree/main/ts-starter#readme and the completed sample here: https://github.com/microsoft/minecraft-scripting-samples/tree/main/ts-starter-complete-cotta; will look to update the docs soon to use all-stable APIs so that we don't run into versioning issues between stable and beta APIs or preview and main versions of Minecraft.