JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 126 of 171 View original ↗
  1. kyonides said:
    Yeap, with the default setup you'd just get that 0.1% of a chance (multiplied by the LUK stat), a very low one indeed.
    With my stats as low as they are (8-30) I am going to playtest a couple of major boosts to this number and I'll see what works.
  2. If I needed help with what to do next with writing a plugin, would I post it here or in JS Plugins In Development?
  3. Powell said:
    If I needed help with what to do next with writing a plugin, would I post it here or in JS Plugins In Development?
    If you need help writing code, here. If you want suggestions on features to add from users, JS Plugins in Development
  4. 1688083643766.png
    I'm trying to do something like this and so far I think I have it correct, so what steps would I need to take to make it display on actors?
  5. Powell said:
    View attachment 267406
    I'm trying to do something like this and so far I think I have it correct, so what steps would I need to take to make it display on actors?
    What do you mean by display on actors? Which screen specifically and where? There are various plugins that let you create custom windows and place them in different scenes.
  6. Powell said:
    If I needed help with what to do next with writing a plugin, would I post it here or in JS Plugins In Development?
    If it's about a specific plugin (even if it's your own plugin), you should probably create your own thread. This thread is moreso meant for general JavaScript questions that can easily be answered in a simple paragraph or by posting a small code snippet.

    If it's the type of thing that might require a back-and-forth discussion, this isn't really a good place for it. Imagine if like 5 different back-and-forth discussions are taking place here at the same time. It would become very confusing.
  7. Is there a way to make events have passability from specific directions like with tiles? Need an event the player can touch (Same as Characters) Priority when moving left and right, but they also need to be able to move through the event when moving up and down.
  8. FrozenFacade said:
    Is there a way to make events have passability from specific directions like with tiles? Need an event the player can touch (Same as Characters) Priority when moving left and right, but they also need to be able to move through the event when moving up and down.
    1688255718937.png
    Just run the command Through On and turn it off when you're done.
  9. For left and right:
    if($gameMap.event(x).isMoving() && ($gameMap.event(x)._direction == 4 || $gameMap.event(x)._direction ==6 )) {$gameMap.event(x).setPriorityType(priority);
    }

    priority is 0 for below, 1 for same as characters, 2 for above

    For up and down use direction 2 and 8
  10. AquaEcho said:
    For left and right:
    if($gameMap.event(x).isMoving() && ($gameMap.event(x)._direction == 4 || $gameMap.event(x)._direction ==6 )) {$gameMap.event(id).setPriorityType(priority);
    }

    priority is 0 for below, 1 for same as characters, 2 for above

    For up and down use 2 and 8

    Thanks I'll mess around with this and see what I can do.
  11. I've been trying to avoid the game to bypass an unselectable Choice when Cancel is pressed and that choice is the Preset Choice for Cancel.
    I managed to do it IF the player has a choice highlighted but if I put (none) in the Default Choice and the player press Cancel BEFORE selecting any Choice the Cancel Choice bypass the plugin block.

    How can I stop that? I thought no choice selected was "Index -1" but it seem to not be working
  12. Winthorp said:
    if I put (none) in the Default Choice and the player press Cancel BEFORE selecting any Choice the Cancel Choice bypass the plugin block.
    We would have to see your code to answer your question, but it's confusing because you shouldn't need any code.

    In your Show Choices command, you set the Cancel Choice to Disallow (or however it's labeled in your language). Then the player can sit there hitting Cancel all day long and nothing will happen. You don't need any plugin for that.
    Screenshot 2023-07-07 135402.png
  13. I made a plugin that disables choices based on tags in the Choice Text so it alters the functionality of the Show Choice box
    I know that you can disallow the Cancel choice via RMMZ but since anyone can use I would like to make it foolproof.

    I managed to deny the cancel condition if the associated condition is disabled (but it needs the player to be on a Choice)
    I managed to remove a bug when the player would click ok when no choice was selected
    But when both are combined (no choice selected and the player use Cancel while it point to a Disabled Choice) I can't avoid the code bypass the Disabled criteria


    JavaScript:
        const _Window_ChoiceList_processEscape = Window_ChoiceList.prototype.processEscape;
        Window_ChoiceList.prototype.processEscape = function() {
          if (this.isCurrentItemEnabled()) {
            if (this.index() >= 0) {
              _Window_ChoiceList_processEscape.call(this);
            } else {
              this.playBuzzerSound();
            }
          } else {
            this.playBuzzerSound();
          }
        };

    In the code, when Escape is processed on a Show Choice, the SHOULD first check if it's one of the disabled choices, then check if index is more or equal than 0 (AKA having a choice selected) and only then it should allow to process the Escape, but it doesn't work if the player hasn't the cursor on a choice
  14. You can always insert multiple console.log instances throught the function to see exactly where it's breaking down.
  15. I'm trying to come up with a JavaScript expression for a hit formula that will check to see if the target has a particular state. If the target does have that state, the hit formula will take the higher of two random outcomes between 1-20, plus additional modifiers (actor proficiency bonus, MAT modifier, LUK modifier). Otherwise, it's just one random outcome between 1-20 plus the additional modifiers, contested against the target's Armor Class (for which I'm using b.mmp) and the target's AGI modifier. I've come up with this ugly nested conditional, but it results in a miss every time.

    JavaScript:
    (b.isStateAffected(X)) ((roll1 = Math.randomInt(20) + 1) > (roll2 = Math.randomInt(20) + 1) ? (roll1 + Math.round(0.25 * a.level + 1.25) + ((a.luk - 10) / 2) + ((a.mat - 10) / 2)) >= b.mmp + ((b.agi - 10) / 2) : (roll2 + Math.round(0.25 * a.level + 1.25) + ((a.luk - 10) / 2) + ((a.mat - 10) / 2)) >= b.mmp + ((b.agi - 10) / 2))) : (Math.randomInt(20) + 1 + Math.round(0.25 * a.level + 1.25) + ((a.luk - 10) / 2) + ((a.mat - 10) / 2)) >= (b.mmp + ((b.agi - 10) / 2));

    What's wrong with this method? I'm using a plugin that affords any valid JavaScript expression, but I thought to post this here instead of in its own thread because it's more JS-related than plugin related.
  16. bookco said:
    What's wrong with this method?
    As a first piece of advice, you are beyond hog wild with parentheses. I strongly suggest you condense your code to use parentheses where you need them - otherwise, they only make it harder to read your code and you're more prone to errors because you have, like, three in a row and you forgot to close one set.

    bookco said:
    JavaScript:
    (b.isStateAffected(X))
    That doesn't do anything. For one, isStateAffected() expects you to pass in an integer value, the ID of the state. So it's going to look for a variable named X and it won't find it.

    For second, that function itself doesn't do anything. It returns a boolean value, and you're not doing anything with it. You would want to use it as some kind of conditional check, but you just have it hanging by itself.

    bookco said:
    Code:
    ((roll1 = Math.randomInt(20) + 1) > (roll2 = Math.randomInt(20) + 1) ?
    This is a little funky but it's okay. However, you should always declare your variables. Just sticking them out there like this gives them global scope, which is not something you should be using unintentionally. Use let or var.

    bookco said:
    Code:
    (roll1 + Math.round(0.25 * a.level + 1.25) + ((a.luk - 10) / 2) + ((a.mat - 10) / 2)) >= b.mmp + ((b.agi - 10) / 2) : (roll2 + Math.round(0.25 * a.level + 1.25) + ((a.luk - 10) / 2) + ((a.mat - 10) / 2)) >= b.mmp + ((b.agi - 10) / 2))) : (Math.randomInt(20) + 1 + Math.round(0.25 * a.level + 1.25) + ((a.luk - 10) / 2) + ((a.mat - 10) / 2)) >= (b.mmp + ((b.agi - 10) / 2));
    This is wrong because you have too many sections for your ternary operator. That's why your formula is failing, it's generating a syntax error and not actually returning a usable value.

    The syntax for the ternary operator is condition ? true result : false result but you have a second colon for...I don't know, something. I'm not sure under what circumstances you intended that code to be executed.

    Another thing I'll put out there is that you keep repeating chunks of code there, and I don't really know why. You have this huge thing:
    Code:
     Math.round(0.25 * a.level + 1.25) + ((a.luk - 10) / 2) + ((a.mat - 10) / 2)) >= b.mmp + ((b.agi - 10) / 2)
    sprawling in there three times. Why?

    If all you're trying to do is roll with advantage if the target has a particular state, you'd do this:
    Code:
    let roll = Math.randomInt(20)+1; roll = target.isStateAffected(insert_state_id_here) ? Math.max(roll, Math.randomInt(20)+1) : roll; roll + Math.round(0.25 * a.level + 1.25) + (a.luk - 10) / 2 + (a.mat - 10) / 2 >= b.mmp + (b.agi - 10) / 2
    where you replace the ID of the state as appropriate - no leading zeros.

    That makes the hit roll; if the target doesn't have the state, you keep the rolled value; otherwise, you see if another roll has a higher result.

    Then you add your modifiers and do the comparison to generate a boolean - lopping off whatever parentheses aren't needed.
  17. Thanks for the usual clarity. You're always a major help and thanks to you I'm coming a long way with my work in JS. The only thing I'll mention is that you wrote:
    ATT_Turan said:
    That doesn't do anything. For one, isStateAffected() expects you to pass in an integer value, the ID of the state. So it's going to look for a variable named X and it won't find it.
    Whereas I had just put X to reference any state whatever, 6, 19, what have you, for the purposes of illustration. Sorry about the confusion.

    I suppose I'll add, you wrote target. Did you mean b or does target work here?
  18. bookco said:
    I suppose I'll add, you wrote target. Did you mean b or does target work here?
    Well, it depends on the plugin you're putting it into. It should tell you in the documentation what you can use - if you know a and b work, go ahead and do that. target is a very commonly supplied variable by plugins that interface with battle.

    (if it's my HitFormula plugin, yes, target will work, even though it doesn't say so :stickytongue:)
  19. @ATT_Turan, I tried what you suggested, and it seems that now there's a 100% hit rate, even with an impossibly high Armor Class. I've tried with both target and b. This also happened when I tried my other method, which was to check the state in a JS Pre-Apply notetag and to add a state that would increase accuracy by 16.6% (roughly translating to rolling with advantage).
  20. @bookco I'd suggest making a separate thread in plugin support, then (or, again, if this is regarding my plugin you can use that thread).

    A basic troubleshooting measure you can do is this change:
    Code:
    let roll = Math.randomInt(20)+1; roll = target.isStateAffected(insert_state_id_here) ? Math.max(roll, Math.randomInt(20)+1) : roll; roll += Math.round(0.25 * a.level + 1.25) + (a.luk - 10) / 2 + (a.mat - 10) / 2; let ac = b.mmp + (b.agi - 10) / 2; console.log("Roll is ", roll, " AC is ", ac); roll >= ac

    Then you can hit F12 and go to the Console tab to see the numeric values it's using for roll and AC.