Problem showing picture using "gameMap._mapId" as part of image name

● ARCHIVED · READ-ONLY
Started by JDevain 3 posts View original ↗
  1. Hello, all. I'm trying to show a different image depending on which map you are on. For example, if you are on map 43, then I want to show the image "minimap_43.png". To do this I'm using:

    Script : $gameScreen.showPicture(15, "minimap_$gameMap._mapId", 0, 0, 0, 100, 100, 255, 0)

    but I get the error: "Failed to load: img/pictures/minimap_$gameMap._mapId.png", so it looks like it's interpretting "$gameMap._mapId" literally. I've tinkered with it a bit, but I'm at a loss. Anyone know what I'm doing wrong?

    Thanks!
  2. As currently wrriten, this is a String literal (meaning, it's literally a string)
    Code:
    "minimap_$gameMap._mapId.png"
    Javascript has no idea that you want the inside to have variable content, it just thinks it's a string.

    You can use template strings to make it have variable content:
    Code:
    `minimap_${$gameMap._mapId}.png`

    Or if you're using an old version of MV that doesn't support modern Javascript, look up string concatenation for Javascript.
  3. Thanks so much for the super fast reply! It's working now.