#custom command not registering

1 messages · Page 1 of 1 (latest)

still current
#

can someone help me? it doesn't even show the console warn message. no errors appearing too.

  • using 2.1.0 api
  • everything is well imported, the file works i even tried to console warn outside of the scope and its fine, its just this thing doesnt work
system.beforeEvents.startup.subscribe(({ customCommandRegistry }) => {
    console.warn("test")
    customCommandRegistry.registerEnum("ap:sellOptions", ["all", "menu"]);

    customCommandRegistry.registerCommand(
        {
            name: "ap:sell",
            description: "Sell items or open the sell menu.",
            permissionLevel: CommandPermissionLevel.Any,
            cheatsRequired: false,
            mandatoryParameters: [
                {
                    name: "ap:sellOptions",
                    type: CustomCommandParamType.Enum,
                },
            ],
        },
        (origin, option) => {
            const player = origin.player;
            if (!player) {
                return { status: CustomCommandStatus.Failure };
            }

            if (option === "all") {
                system.run(()=>{
                    sellAll(player);
                })
            } else if (option === "menu") {
                system.run(()=>{
                    openSellMenu(player);
                })
            }
            return {
                status: CustomCommandStatus.Success,
            };
        }
    );
});
still current
#

okay, so I found the problem, its because of importing at the same file where the startup is

this is my whole code that had the problem:

import { world, system, CommandPermissionLevel, CustomCommandParamType, CustomCommandStatus } from "@minecraft/server";

//these, im importing it outside which makes the startup not work
import { sellAll } from "./sell/sell_all.js"; 
import { openSellMenu } from "./sell/sell_ui.js";

world.afterEvents.worldLoad.subscribe(async () => {
  import("./core.js");
});

system.beforeEvents.startup.subscribe(({ customCommandRegistry }) => {
  customCommandRegistry.registerEnum("ap:sellOptions", ["all", "menu"]);

  customCommandRegistry.registerCommand(
    {
      name: "ap:sell",
      description: "Sell items or open the sell menu.",
      permissionLevel: CommandPermissionLevel.Any,
      cheatsRequired: false,
      mandatoryParameters: [
        {
          name: "ap:sellOptions",
          type: CustomCommandParamType.Enum,
        },
      ],
    },
    (origin, option) => {
      const player = origin.sourceEntity;
      if (!player) {
        return { status: CustomCommandStatus.Failure };
      }

      if (option === "all" && sellAll) {
        system.run(() => {
          sellAll(player);
        });
      } else if (option === "menu" && openSellMenu) {
        system.run(() => {
          openSellMenu(player);
        });
      }

      return {
        status: CustomCommandStatus.Success,
      };
    }
  );
});
#

so this fixed it

let sellAll;
let openSellMenu;

world.afterEvents.worldLoad.subscribe(async () => {
    ({ sellAll } = await import("./sell/sell_all.js"));
    ({ openSellMenu } = await import("./sell/sell_ui.js"));
    import("./core.js");
});
quasi herald
#

This is very strange you claim that importing these in the same file as where you registering the custom command is causing the custom command to not register but that makes no sense as the only way the command would not register is if the a parameter failed to register such as a custom enum or if you put a capital letter in the identifier for the command or for the custom enum since the stuff that you're importing is used in the command but it's only used after the command is executed it shouldn't have any bearing on the command being registered.

#

I mean if running is asynchronous function works for you then that's fine but it's just strange to me. Also can you please mark this as resolved since you've already resolved this issue @still current

still current
# quasi herald This is very strange you claim that importing these in the same file as where yo...

the event doesnt work even with undeclared variables

//these, im importing it outside which makes the startup not work
import { sellAll } from "./sell/sell_all.js"; 
import { openSellMenu } from "./sell/sell_ui.js";

world.afterEvents.worldLoad.subscribe(() => {
  import("./core.js");
});

system.beforeEvents.startup.subscribe(({ customCommandRegistry }) => {
  asdasdasd
  asdasdasdasd
  asd().dasda
  //no errors appearing on console
});
still current