JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 162 of 171 View original ↗
  1. taromil said:
    I'm using MV, and I need to check whether one variable is equal to another variable plus or minus one. In other words, I need to check (as an if statement) if variable1 = variable2+1 some times, and variable1 = variable2-1 other times. As far as I know there isn't a way to do this through basic event commands, so I'll need to use JS. The only way I can think to do this is making 3 versions of variable2, the basic one and two that are one more and one less than it, but with all the different situations that need their own version of variable2, that would result in way way more variables than I'd like to work with. Is there a script or something I could use?
    Conditional branch -> script call.
    ($gameVariables.value(1) == $gameVariables.value(2) + 1) || ($gameVariables.value(1) ==
    $gameVariables.value(2) - 1)
  2. taromil said:
    As far as I know there isn't a way to do this through basic event commands
    you can. you use a 3rd variable, set it to the 2nd, add or subtract 1, and then compare variable 1 to 3. even if you need to check other variables, you dont change the id of variable 3
  3. Robro33 said:
    you can. you use a 3rd variable, set it to the 2nd, add or subtract 1, and then compare variable 1 to 3. even if you need to check other variables, you dont change the id of variable 3
    I'm sorry, I should've been more specific. What I meant was I know how to do it without scripting, but since my particular project would then require way more variables than I want to work with, I needed to figure out how to achieve the same result through scripting.
    Hyouryuu-Na said:
    Conditional branch -> script call.
    ($gameVariables.value(1) == $gameVariables.value(2) + 1) || ($gameVariables.value(1) ==
    $gameVariables.value(2) - 1)
    Thank you! I know it's super simple, but I haven't learned JS yet and have little experience with RPG Maker in general. It works exactly how I needed :)
  4. The script for checking the value of variables is

    $gameVariables.value(variable ID)

    E.g

    JavaScript:
    $gameVariables.value(y) == $gameVariables.value(x) + 1

    EDIT: lol, sorry, replied without flipping the page.

    EDIT2: you could also do this

    JavaScript:
    Math.abs($gameVariables.value(y) - $gameVariables.value(x)) == 1
  5. taromil said:
    I'm using MV, and I need to check whether one variable is equal to another variable plus or minus one. In other words, I need to check (as an if statement) if variable1 = variable2+1 some times, and variable1 = variable2-1 other times. As far as I know there isn't a way to do this through basic event commands, so I'll need to use JS. The only way I can think to do this is making 3 versions of variable2, the basic one and two that are one more and one less than it, but with all the different situations that need their own version of variable2, that would result in way way more variables than I'd like to work with. Is there a script or something I could use?
    Would the following accomplish what you're looking for with built in commands?
    1743010453694.png
  6. I've got a very stupid and honestly quite dumb question.. but for the life of me, i'm just not sure..
    setBlendColor([0, 100, 200, 255]);
    Which is which?
    I'm adjusting the collapse animation for enemies.. and i'm kinda confused on which is which >_<
    I assume 3 of them are Red Blue and Green, but i'm not sure which is the intensity..
  7. MikePjr said:
    I assume 3 of them are Red Blue and Green, but i'm not sure which is the intensity..
    These are R G B A, in that order.
  8. Nate_Tillern said:
    Would the following accomplish what you're looking for with built in commands?
    Sorry for taking so long to respond! I was super busy and couldn't check the forums lol
    That would work, but the problem is my project has a lot of these variables, so doing it this way would triple the amount I would need for the game to run, and it would just be way too much of a hassle. I might end up using this for a different part of the project, but for now I'll continue with script calls.
  9. Back again haha
    I'm sure the answer is super simple, but I can't find it anywhere. I need an event to check whether its x position is equal to a variable, how can I do that?
  10. Either in its event page
    If: this.character(0).x == $gameVariables.value(12)

    Or in a move route
    if(this.x ==$gameVariables.value(12)){script you want to happen here}

    Where 12 is the variable number
  11. taromil said:
    I'm using MV, and I need to check whether one variable is equal to another variable plus or minus one. In other words, I need to check (as an if statement) if variable1 = variable2+1 some times, and variable1 = variable2-1 other times. As far as I know there isn't a way to do this through basic event commands, so I'll need to use JS. The only way I can think to do this is making 3 versions of variable2, the basic one and two that are one more and one less than it, but with all the different situations that need their own version of variable2, that would result in way way more variables than I'd like to work with. Is there a script or something I could use?
    Here is an example of what you can use as a script condition. I've used variables id 2 and 4 here:
    Math.abs($gameVariables.value(2) - $gameVariables.value(4)) <= 1
    Math.abs turns the difference between the two variable values into a positive number, so -1 becomes +1.

    Oh I was too late to answer.
    I did not scroll down, sorry.
  12. BurningOrca said:
    Here is an example of what you can use as a script condition. I've used variables id 2 and 4 here:
    Math.abs($gameVariables.value(2) - $gameVariables.value(4)) <= 1
    Math.abs turns the difference between the two variable values into a positive number, so -1 becomes +1.

    Oh I was too late to answer.
    I did not scroll down, sorry.
    Don't worry about it, because your answer is actually useful for a different part of my project! I must have great luck to get a question answered without even asking it yet haha
  13. Is there a way to get the last gold gained by the player?
  14. SolemnGravity said:
    Is there a way to get the last gold gained by the player?
    If you're only adding gold via event commands then you can track it manually, using a variable.

    Otherwise you would need a plugin, e.g. (untested):
    plugin code
    JavaScript:
    /*:
     * @target MV MZ
     * @plugindesc Adds script call: $gameParty.recentGold
     * @author Caethyril
     * @url https://forums.rpgmakerweb.com/posts/1507920
     * @help Use in a Script field to get the most recent gold gain/loss:
     *    $gameParty.recentGold
     * Gold gains/losses are grouped by:
     *    - Troop, for battle drops;
     *    - Item (either single or bulk transaction), for shops;
     *    - Command, for the Change Gold event command.
     *
     * Free to use and/or modify for any project, no credit required.
     */
    ;void (function() {
      /** New identifier for "recent gold" property on `Game_Party`. */
      const P = "recentGold";
    
      // Patch - init value.
      void (function(alias) {
        Game_Party.prototype.initialize = function() {
          alias.apply(this, arguments);
          this[P] = 0;
        };
      })(Game_Party.prototype.initialize);
    
      // Patch - update value.
      void (function(alias) {
        Game_Party.prototype.gainGold = function() {
          const pre = this._gold;
          alias.apply(this, arguments);
          this[P] = this._gold - pre;
        };
      })(Game_Party.prototype.gainGold);
    
    })();
    Otherwise I suggest starting a new thread in Plugin Requests~
  15. taromil said:
    Sorry for taking so long to respond! I was super busy and couldn't check the forums lol
    That would work, but the problem is my project has a lot of these variables, so doing it this way would triple the amount I would need for the game to run, and it would just be way too much of a hassle. I might end up using this for a different part of the project, but for now I'll continue with script calls.
    Scripting is totally fine of course (in fact, I would recommend it over eventing here because of how unwieldy that could become, even if you set up a common event to call that runs the comparison instead of creating an if-else chain every time).

    But I did want to flag that the method I showed you should not triple your number of variables, it should only add 3 (ComparisonVar, VIQ+1, and VIQ-1) on top of the ones you already have since those don't need to hold values permanently, just during a comparison check, so can be used repeatedly for all other variables.
  16. Nate_Tillern said:
    But I did want to flag that the method I showed you should not triple your number of variables, it should only add 3 (ComparisonVar, VIQ+1, and VIQ-1) on top of the ones you already have since those don't need to hold values permanently, just during a comparison check, so can be used repeatedly for all other variables.
    Oh I'm sorry, I misunderstood. Other people on the forums and outside have recommended making two extra variables per original variable, so I must've assumed that's what you meant.
  17. Hey everyone. Im using rpg maker mv and am currently attempting to find a way in battle to use one skill to interrupt another one. Basically if A uses the skill "Attack" and B tries to use the skill "Heal":
    A attacks B first , then a log message is displayed "B got interrupted and cant heal" and then B doesnt heal, however if A doesnt use "Attack" then the log message is not displayed and the skill "Heal" heals the user ( B in this case ).

    My first idea was to give the "Attack" skill a priority of 1000 so it always goes first and have "Attack" apply a status that has Seal Skill "Heal". And it mostly works as planned. A attacks , B takes damage , B gets sealed and cant use "Heal" - However it is not transparent for the player because I dont know how to display the log message. If I include it in "Attack" it triggers even if the attacked player doesnt use "Heal" and I cant include it in "Heal" because the skill gets sealed before resolving. Maybe a common event could help but Im not sure how to write it.

    Im not even sure anymore if the idea of using seal skill even works to begin with or if I just need to rewrite how "Attack" and "Heal" work.

    Im pretty new to rpg maker and would appreciate any help. Thanks in advance
  18. Hi, I'm trying to make a skill where it gives buffs to Character A, but after it expires, it gives debuffs to Character A, like a downside exhaustion effect.

    Does anyone know what JavaScript I need to write under JS On Expire State, or know where I could find help on learning how to write it? Thanks!
  19. when you say buffs, do you mean buffs or states? there isnt a trigger you could use for buffs expiring but you can use a state with the same duration as the buff to fake one, use
    Code:
    user.addDebuff(2,5)
    , and then add extra lines and change the 2 for the parameter ids for what you want debuffed

    if you did mean that its a state that gives another state when it expires put in
    Code:
    user.addState(x)
    into the expire effect and itll apply state x