public

Rpg Maker Developers Group

Simple enough for a child, powerful enough for a developer

2 Followers

MZ RPG Maker MZ Javascript Show Choices Help

BMM Archive · July 15, 2026

Preserved forum archive. This topic stores the original first post and locally mirrored RPG Maker Web attachments when available. It is posted by the BMMPlay archive account, not by the original creator.

Original Source

  • Original title: MZ RPG Maker MZ Javascript Show Choices Help
  • Original author: icycold2367
  • Original date: February 7, 2024
  • Source thread: https://forums.rpgmakerweb.com/threads/rpg-maker-mz-javascript-show-choices-help.165548/
  • Source forum path: Game Development Engines > RPG Maker Javascript Plugins > Learning Javascript

Summary

For those still searching in the future. I figured a solution. Not sure about why it's still a problem biut found a workaround that works. This allows items to add conditional branch just off of being in the inventory. It isn't complete but it works for what I needed it for. [CGMZ] Conditional Choices for RPG Maker MZ by Casper Gaming Add conditions to choices in the choice window casper-gaming.itch.io

Archived First Post

For those still searching in the future. I figured a solution. Not sure about why it's still a problem biut found a workaround that works. This allows items to add conditional branch just off of being in the inventory. It isn't complete but it works for what I needed it for.


This is also a valid option as well.
Thank you @AquaEcho
Thank you @Trihan

Little Backstory,
I was wondering if someone would be able to assist me in debugging why this function is not working? I'm not a master programmer and alot of this is written with ChatGPT's help on some things. My goal of this is that it will display the names of the seeds that are currently in your inventory and when selected perform the common event that the constant assigned to them.

Current Problem,
- Does not display any of the choices ingame. Just a blank menu I can exit out of.

How I call this is with a script in an event by just calling the function

Code:
function checkSeedAvailability() {
    const seedCommonEvents = [
        { name: "Carrot Seeds", eventId: 125 },
        { name: "Corn Kernals", eventId: 123 },
        { name: "Potato Sprouts", eventId: 122 },
        { name: "Cabbage Seeds", eventId: 124 },
        { name: "Radish Seeds", eventId: 126 },
        { name: "Onion Seeds", eventId: 127 },
        { name: "Strawberry Seed", eventId: 128 },
        { name: "Pumpkin Seeds", eventId: 129 },
        { name: "Bean Seeds", eventId: 130 },
        { name: "Cashew Seeds", eventId: 131 },
        { name: "Tomato Seeds", eventId: 132 },
        { name: "Wheat Seeds", eventId: 133 },
        { name: "Zuchinni Seeds", eventId: 134 },
        { name: "Lettuce Seeds", eventId: 135 },
        { name: "Blueberry Seeds", eventId: 136 },
        { name: "Broccoli Seeds", eventId: 137 },
    ];

    const isEquippedWithSeedBag = $gameParty.leader().equips().some(function (equip) {
        return equip && equip.meta.SeedBag === 'true';
    });

    if (isEquippedWithSeedBag) {
        const availableSeeds = $dataItems.filter(function (item) {
            return item && $gameParty.numItems(item) > 0;
        });

        const seedChoices = availableSeeds.map(function (seed) {
            return seed.name;
        });

        if (seedChoices.length > 0) {
            $gameMessage.setChoices(seedChoices, 0, -2, 0);
            $gameMessage.setChoiceCallback(function (choiceIndex) {
                if (choiceIndex === -2) {
                    $gameTemp.reserveCommonEvent(20);
                    return;
                }

                const selectedSeed = availableSeeds[choiceIndex];
                const selectedSeedName = selectedSeed.name;

                const selectedEventId = seedCommonEvents.find(seed => seed.name === selectedSeedName)?.eventId;

                if (selectedEventId) {
                    $gameTemp.reserveCommonEvent(selectedEventId);
                } else {
                    $gameMessage.add(`You planted ${selectedSeedName}!`);
                }

                const selectedSeedId = selectedSeed.id;
                $gameParty.gainItem($dataItems[selectedSeedId], -1);
            });
        } else {
            $gameMessage.add("You don't have any seeds.");
        }
    } else {
        $gameMessage.add("You need to equip a Seed Bag weapon to plant seeds.");
    }
}

Downloads / Referenced Files

Log in to download

Log in, then follow the RPG Maker Developers Group to see these download links.

Log in to download

Referenced Images / Attachments

casper-gaming.itch.io
casper-gaming.itch.io
casper-gaming.itch.io
casper-gaming.itch.io
forums.rpgmakerweb.com
forums.rpgmakerweb.com
Creator Claims / Removal

If you are the original creator and want this listing reassigned, edited, or removed, join BMMPlay and contact the moderators with proof that matches the original RPG Maker Web profile, linked GitHub, itch.io page, or another public creator identity.

#039#rpg-maker-archive#js-learning

Replies (0)

No replies yet.

0 replies 1 view

Log in to reply.

User Avatar