JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 128 of 171 View original ↗
  1. Hey there! I'm trying to implement a bin system like in stardew valley and harvest moon, wherein a player places all the items they want to sell in a storage. Therafter, all the items sold will be displayed with icons, item name, item amount, and selling price. I have managed to implement it to a certain extent, however, when the item price is equal to or over 1000, the alignment goes off (See picture)

    EDIT: I have tried to make a conditional branch that if selling price is over 1000, one space will be deleted between item icon and item name, to no avail.

    The code is provided here:
    CODE
    (function() {
    function getItemIcon(item) {
    return '\\i[' + item.iconIndex + ']';
    }

    function displayStorageItems() {
    const storage = $gameStorageSystems.storage(0); // Change 0 to the desired storage system id
    const items = storage.allItems().map(e => {
    const itemIcon = getItemIcon(e);
    const itemName = e.name;
    const itemAmount = "x" + storage.numItems(e);
    const sellingPrice = e.price * storage.numItems(e);
    const sellingPriceStr = sellingPrice >= 1000 ? sellingPrice + 'G' : sellingPrice + 'G';
    return [itemIcon, itemName, itemAmount, sellingPriceStr];
    });

    const colLengths = getColLengths(items);

    const formattedItems = items.map(e => e.map((item, i) => {
    let elementLength = item.replace(/\x1b\[\d+\]/g, '').length;
    return item + (' '.repeat(colLengths - elementLength));
    }));

    const result = formattedItems.map(e => e.join(' ')).join("\n");

    $gameMessage.setBackground(1);
    $gameMessage.setPositionType(1);
    $gameMessage.add(result);

    const totalSellingPrice = storage.allItems().reduce((t, e) => t + e.price * storage.numItems(e), 0);
    $gameMessage.add('\nTotal Selling Price: ' + totalSellingPrice + 'G');
    }

    function getColLengths(items) {
    const iconLengths = items.map(e => e[0].replace(/\x1b\[\d+\]/g, '').length);
    const nameLengths = items.map(e => e[1].replace(/\x1b\[\d+\]/g, '').length);
    const amountLengths = items.map(e => e[2].replace(/\x1b\[\d+\]/g, '').length);
    const priceLengths = items.map(e => e[3].replace(/\x1b\[\d+\]/g, '').length);

    return [
    Math.max(...iconLengths),
    Math.max(...nameLengths),
    Math.max(...amountLengths),
    Math.max(...priceLengths)
    ];
    }

    window.displayStorageItems = displayStorageItems;
    })();
  2. DuraLexSedLex said:
    Hey there!
    Hey. When you post code, you need to use the CODE tags (the </> in the edit bar).

    That will preserve indentations and also prevent brackets from being interpreted as BBCode. See how halfway through your code must have an [i]? It turns into italic, and everywhere you have that it's not printed.
  3. Hi, could someone please tell me why this weapon notetag is having no effect when I test it in a battle? I'm an MZ user with the VisuStella 8 Waves Bundle (though half of them are disabled).

    The weapon is supposed to give the actor 1 MP on a successful hit that does damage:

    Code:
    <JS Post-Damage As User>
    // Check if this action deals HP damage
    if (this.isHpEffect() && value > 0) {
      // Give Saylor 1 MP
      user.gainMp(1);
    }
    <JS Post-Damage As User>

    I have zero coding ability, so I'm assuming the issue relates to my attempt to repurpose a code from another skill.
  4. @tumsterfest You're not correctly closing the notetag with a forward slash in the name.
  5. Hey everyone, I've got a question concerning Visustella's Comment Event Menu plugin https://visustellamz.itch.io/common-event-menu. I was wondering if it would be possible to create this menu using that plugin? If not, could I get some recommendations? Thanks!
    menu mockup.png
  6. ATT_Turan said:
    @tumsterfest You're not correctly closing the notetag with a forward slash in the name.

    Thanks! I didn't know that was a requirement for conditional notetags. Good thing I only spent 2.5 hours trying to make the weapon work last weekend.
  7. Hey, I'm making a "Stat and Skill" plugin and for now I used a "not so elegant" custom Actor Selection Window to choose what Actor to analyze.
    What I would like to do is to have a behaviour similar to Equip or Skill Command, that let the player select and Actor from the MENU list of Actors and then call the Scene.
    Is there a function to use that follows this behaviour? I tried to roam between the Class and Windows core JS but didn't find a way
  8. I don't get how Screen Shake Power and Speed work at all. If I set it to 1 and 1, nothing happens. If I set it to 2 and 2 it goes super fast. If I set it to 5 and 5 it goes at a medium pace (but I need it slower) and if I set it to 9 and 9 it goes faster but not as fast as 1 and 1:1690635852959.png
  9. coldReactive said:
    I don't get how Screen Shake Power and Speed work at all.
    This question is not related to using JavaScript at all.

    You're asking about parameters from a specific plugin, and per the first post in this thread, it's not for support with plugins.

    You'll get better responses making a thread in Plugin Support asking people who have used the plugin. Or contacting VisuStella support (presuming it's not described in the instructions).

    tumsterfest said:
    Thanks! I didn't know that was a requirement for conditional notetags.
    It doesn't have anything to do with "conditional notetags," although I'm not sure exactly what you mean by that.

    It is specified in the plugin's instructions.

    1690648796768.png

    That's standard practice for all plugins that allow for multiple lines in a notetag - the parser needs some way to know that the tag is ending.
  10. ATT_Turan said:
    This question is not related to using JavaScript at all.

    You're asking about parameters from a specific plugin, and per the first post in this thread, it's not for support with plugins.

    You'll get better responses making a thread in Plugin Support asking people who have used the plugin. Or contacting VisuStella support (presuming it's not described in the instructions).
    The problem is, it has the same exact effect with the shake vanilla RPG Maker has. 1 and 1 does nothing, etc. But I'll do that.
  11. Yeah, that was my confusing way of saying "notetags that require conditional logic or other stuff that requires multiple lines," haha. Until recently, I'd only used simple stuff like <HP Cost: 100>, so I wasn't familiar with the forward slash. Thanks for the clarification.
  12. adilene said:
    Hey everyone, I've got a question concerning Visustella's Comment Event Menu plugin https://visustellamz.itch.io/common-event-menu. I was wondering if it would be possible to create this menu using that plugin? If not, could I get some recommendations? Thanks!
    View attachment 270229
    Theoretically, yes, you should be able to make it. Just use the template closest to your design. Alternatively modify the main menu as there are different plugins to do that.

    However, this isn't really a Javascript question so you may want to make a separate thread in plugin support.
  13. Hi all,

    I need help! I'm making a plugin that shows some pictures on screen when called and the player can select them with arrow keys and "ok" action.
    The picture part of the plugin work great but since everything is done on the map instead than calling a Scene, the player can still move and interact with the map while the plugin is working.

    I want the player to freeze, no movements no interaction as long as I need it.
    So far I manage to make the player unable to move the character when a certain function is called but he still can interact with an event when next to it.

    Any hint or tip?
  14. Winthorp said:
    Any hint or tip?
    1 - Turn it into its own Scene :stickytongue:

    2 - Call the whole thing from an autorun event, that disables player movement.

    3 - Alias the game's input methods and add some reference to what you've made, whether it's the presence of a variable or you can turn a switch on and off so that it doesn't go through to the default movement/activation functions.
  15. ATT_Turan said:
    1 - Turn it into its own Scene :stickytongue:

    2 - Call the whole thing from an autorun event, that disables player movement.

    3 - Alias the game's input methods and add some reference to what you've made, whether it's the presence of a variable or you can turn a switch on and off so that it doesn't go through to the default movement/activation functions.

    Sadly I cannot make it his own scene as the plugin is built to read the map and let the player fight by moving events and assigning event to allied and enemies.

    Calling it by autoevent actually works but I wanted to make something easier to understand for others, still this is a doable way, thanks!

    I tried several ways to mod key behaviour like:

    To disable "ok":

    JavaScript:
    // Add this above the rest of your code
    var aliasInputIsTriggered = Input.isTriggered;
    
    // Override the Input.isTriggered method
    Input.isTriggered = function(keyName) {
        if (!this.isEnabled) {
            // If inputs are locked, return false for all keys except "ok"
            if (keyName === "ok") {
                // Call your specialCommand function here with "ok" as an argument
            }
            return false;
        } else {
            // If inputs are not locked, use the original Input.isTriggered logic
            return aliasInputIsTriggered.call(this, keyName);
        }

    To disable everything but "left/right/ok/cancel":
    JavaScript:
    Input.isPressed = function(arg) {
        if (this.isEnabled) {
            return alias2.call(this, arg);
        } else {
            if (arg === 'right' || arg === 'left' || arg === 'ok' || arg === 'cancel') {
                specialCommand(arg);
            }
            return false;
        }
    }

    But he acts like the key is always pressed
  16. Winthorp said:
    Sadly I cannot make it his own scene as the plugin is built to read the map and let the player fight by moving events and assigning event to allied and enemies.

    Calling it by autoevent actually works but I wanted to make something easier to understand for others, still this is a doable way, thanks!

    I tried several ways to mod key behaviour like:

    To disable "ok":

    JavaScript:
    // Add this above the rest of your code
    var aliasInputIsTriggered = Input.isTriggered;
    
    // Override the Input.isTriggered method
    Input.isTriggered = function(keyName) {
        if (!this.isEnabled) {
            // If inputs are locked, return false for all keys except "ok"
            if (keyName === "ok") {
                // Call your specialCommand function here with "ok" as an argument
            }
            return false;
        } else {
            // If inputs are not locked, use the original Input.isTriggered logic
            return aliasInputIsTriggered.call(this, keyName);
        }

    To disable everything but "left/right/ok/cancel":
    JavaScript:
    Input.isPressed = function(arg) {
        if (this.isEnabled) {
            return alias2.call(this, arg);
        } else {
            if (arg === 'right' || arg === 'left' || arg === 'ok' || arg === 'cancel') {
                specialCommand(arg);
            }
            return false;
        }
    }

    But he acts like the key is always pressed
    What is "specialCommand"?
  17. Winthorp said:
    I tried several ways to mod key behaviour like:
    I wouldn't suggest doing it at such a low level. Instead of looking at isTriggered() and messing with how the engine reads input generally, put the check in the specific things you want to disable.

    For example, Game_Player.triggerButtonAction()
  18. Trihan said:
    What is "specialCommand"?
    It will be a function that handles the "ok" input in different ways based on what part of the plugin is running (for example if the player is choosing a card it will select that card)
    ATT_Turan said:
    I wouldn't suggest doing it at such a low level. Instead of looking at isTriggered() and messing with how the engine reads input generally, put the check in the specific things you want to disable.

    For example, Game_Player.triggerButtonAction()
    Thanks, I'll give it a try!
  19. Winthorp said:
    It will be a function that handles the "ok" input in different ways based on what part of the plugin is running (for example if the player is choosing a card it will select that card)

    Thanks, I'll give it a try!
    And alias2?
  20. Trihan said:
    And alias2?
    The alias for InputPressed

    JavaScript:
    var alias2 = Input.isPressed;