I can't fix this error

Question: Why is it showing the following error?

TypeError: Cannot read properties of undefined (reading ':')

I have tried changing the name, but it doesn’t work. What’s wrong?

Repl link: replit.com/@element1010/Confidential-Repl#script.js

scene("game", (levelset, level) => {
  const levels = {
    earth: [
      [
        ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::",
        "                                                               ",
        "                                                               ",
        "                                                               ",
        "                                                               ",
        "                                                               ",
        " @    U         U      U      U   ^        U       ^         U ",
        "==============================================================="
      ]
    ]
  };

  const cLevel = addLevel(levels[levelset][level], {
    tileWidth: 64,
    tileHeight: 64,
    "@": () => [
      sprite("player"),
      area(),
      body(),
      move(320, 0),
      "player"
    ],
    "=": () => [
      sprite("tile-="),
      area(),
      body(),
      solid(),
      "tile"
    ],
    ":": () => [
      sprite("tile-:"),
      area(),
      body(),
      solid(),
      "tile"
    ],
    "U": () => [
      sprite("tile-U"),
      area(),
      body(),
      solid(),
      "tile"
    ],
    "^": () => [
      sprite("tile-^"),
      area(),
      body(),
      solid(),
      "spike"
    ]
  });

  const player = level.get("player");

  onKeyDown("up", () => player.move(0, -320));

  onClick(() => player.move(0, -320));
});

@element1010 found a few things:

  1. Your tiles should be in an object called tiles within the cLevel object[1]
  2. solid() isn’t a function
  3. and level.get isn’t a function either (I assumed that was supposed to be cLevel.get, which works… until you try to move the player, which also isn’t a function)

Anyways, #1 is the issue you were asking about here, I just fiddled with it and found 2 and 3 after that.


  1. https://kaboomjs.com/#addLevel ↩︎

1 Like