JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 64 of 171 View original ↗
  1. Is there a script I can add to a plugin to increase the spacing between commands on the main menu?
    I have made the menu commands as icons but they are too close together and I'm just wondering how I can spread them further apart.
  2. The easiest way to achieve this is to just define a new itemHeight method for Window_MenuCommand.

    Code:
    Window_MenuCommand.prototype.itemHeight = function() {
        return this.lineHeight() + x
    }
    
    //replace x with a value for the extra space you want (eg. 10)
  3. I'm making a skill that is like this: A warlock puts a curse on an enemy. If the enemy is attacked, then the curse is lift, but the enemy loses life and the attacker gains that amount of life. I know that I should use yanfly's buff and states core, and in the state (of the curse) I should put a code between this:

    <Custom Remove Effect>


    </Custom Remove Effect>

    but I have problems checking who the attacker is. Please help. Thanks
  4. Gargoyle77 said:
    I'm making a skill that is like this: A warlock puts a curse on an enemy. If the enemy is attacked, then the curse is lift, but the enemy loses life and the attacker gains that amount of life. I know that I should use yanfly's buff and states core, and in the state (of the curse) I should put a code between this:

    <Custom Remove Effect>


    </Custom Remove Effect>

    but I have problems checking who the attacker is. Please help. Thanks

    Hello, I would use this notetag instead:
    Code:
    <Custom Respond Effect>
    if (this.isPhysical() && target.result().hpDamage > 0) {
       dam = target.result().hpDamage;
       user.gainHp(dam)
       target.removeState(state ID);
    }
    </Custom Respond Effect>
  5. I have a character who is an Alchemist. I have it set up with Victor Engine's Mix Action so that he can combine two items in combat for a predetermined effect.

    What I would like to happen is that when he combines the items, it gets added to a list in the menu that the player can view (but not use; it's a battle skill only). I'm also using YEP_SkillCore, and I thought I could have him "learn" his Alchemy Skills by putting something like this in the notes of each skill:
    <Post-Damage Eval>
    if (!user.isLearnedSkill(skill.id)) {
    user.learnSkill(skill.id);
    var text = user.name() + ‘ discovered the formula for ‘
    text = text + skill.name + ‘!’;
    $gameMessage.add(text);
    }
    </Post-Damage Eval>

    Basically, whenever he mixes an item in battle to get an effect, I want the game to check to see if he already knows the skill, and if not, to add it to the menu for viewing. The above code returns a syntax error, though, and I'm not sure what I'm missing.
  6. BlueBomber000 said:
    <Post-Damage Eval>
    if (!user.isLearnedSkill(skill.id)) {
    user.learnSkill(skill.id);
    var text = user.name() + ‘ discovered the formula for ‘
    text = text + skill.name + ‘!’;
    $gameMessage.add(text);
    }
    </Post-Damage Eval>
    You've got ‘opening/closing’ quote marks there, rather than 'neutral' ones. Try this instead:
    JavaScript:
    if (!user.isLearnedSkill(skill.id)) {
      user.learnSkill(skill.id);
      var text = user.name() + ' discovered the formula for ';
      text += skill.name + '!';
      $gameMessage.add(text);
    }
  7. Need a bit of help understanding something. I have this code here I'm trying to insert into an old method, but I get an error of "cannot read property call is undefined".

    Code:
    const gameActionElementReactionMessageDisplay = Game_Action.prototype.makeDamageVaule;
    Game_Action.prototype.makeDamageValue = function(target,critical) {
      
      gameActionElementReactionMessageDisplay.call(this,target,critical);
      
      if (this.calcElementRate(target) > 0) {
       SceneManager._scene._logWindow.addText("Poop!")      
      };
    
       
    };

    I don't know if it has something to do with the args. I've mainly been using this method on methods without them. But I'm not sure why this call isn't working?
  8. It's makeDamageValue not makeDamageVaule ;)
  9. TheoAllen said:
    It's makeDamageValue not makeDamageVaule ;)

    @TheoAllen - Oh my god. That was it. :eswt:
    Though now nobody's doing any damage. But at least for now, it is saying "Poop".
    So that's progress. Thanks!
  10. caethyril said:
    You've got ‘opening/closing’ quote marks there, rather than 'neutral' ones. Try this instead:
    JavaScript:
    if (!user.isLearnedSkill(skill.id)) {
      user.learnSkill(skill.id);
      var text = user.name() + ' discovered the formula for ';
      text += skill.name + '!';
      $gameMessage.add(text);
    }

    Got it. I tried that and then it gave me a reference error, saying "skill is not defined."

    Screen Shot 2019-12-31 at 7.01.53 PM.png

    So then I thought maybe I needed to specify THIS skill ("THIS" meaning whatever skill effect the user is trying to create), so I tried the following code...

    JavaScript:
    if (!user.isLearnedSkill(this.skill.id)) {
      user.learnSkill(this.skill.id);
      var text = user.name() + ' discovered the formula for ';
      text += this.skill.name + '!';
      $gameMessage.add(text);
    }

    ... which gave me this:
    Screen Shot 2019-12-31 at 7.06.32 PM.png

    ... and I don't know what that means.
  11. BlueBomber000 said:
    Got it. I tried that and then it gave me a reference error, saying "skill is not defined."
    Oh, just checked the code of Yanfly's Skill Core; looks like you should replace skill with item, i.e.
    JavaScript:
    if (!user.isLearnedSkill(item.id)) {
      user.learnSkill(item.id);
      var text = user.name() + ' discovered the formula for ';
      text += item.name + '!';
      $gameMessage.add(text);
    }
  12. I did some more experimentation with my code from yesterday. And I made sure value was spelled right this time! It seems that the damage value gets lost somewhere. Using "return 10" will result in 10 damage. But using "return value" results in an error message that value is undefined.

    Does anybody know why value is undefined if I'm still referencing the old method that has it?

    Code:
    const gameActionElementReactionMessageDisplay = Game_Action.prototype.makeDamageValue;
    Game_Action.prototype.makeDamageValue = function(target,critical) {
      
      gameActionElementReactionMessageDisplay.call(this,target,critical);
      
         
      if (this.calcElementRate(target) > 1) {
        SceneManager._scene._logWindow.addText("They didn't enjoy that all!")  
      };
      
      if (this.calcElementRate(target) < 1) {
       SceneManager._scene._logWindow.addText("They shrugged it off.")     
      };
      
      return value;
    
       
    };
  13. sleepy_sealion said:
    Does anybody know why value is undefined if I'm still referencing the old method that has it?
    Hi, value is undefined because it is not defined anywhere above... You have to declare it inside the function or send it to the function as argument. The function you show above use target and critical as its arguments by default.
  14. Does that mean you can't reference variables from the original methods when you do things like this?
  15. sleepy_sealion said:
    Does that mean you can't reference variables from the original methods when you do things like this?
    Well, if by original method you mean the Game_Action.prototype.makeDamageValue from object.js,
    value is declare inside the function like this:
    var value = baseValue * this.calcElementRate(target);

    One way or the other, if value is not defined either inside the function, in the scope above it or send as an argument, you can't reference it.

    *where do you put that code and how do you call the method?
  16. I'm trying to use it like how you'd use an alias in Ruby. So it is just exactly like how it's posted at the end of my scripts. So it should be getting called when the original makeDamageValue is called.
  17. Code:
    const gameActionElementReactionMessageDisplay = Game_Action.prototype.makeDamageValue;
    Game_Action.prototype.makeDamageValue = function(target,critical) {
      var value = gameActionElementReactionMessageDisplay.call(this,target,critical);
      if (this.calcElementRate(target) > 1) {
        SceneManager._scene._logWindow.addText("They didn't enjoy that all!") 
      };
      if (this.calcElementRate(target) < 1) {
       SceneManager._scene._logWindow.addText("They shrugged it off.")    
      };
      return value;
    };
    Here is what you need to do

    EDIT:
    sleepy_sealion said:
    I'm trying to use it like how you'd use an alias in Ruby.
    Even if it was a Ruby code, you will still get undefined method error. The same logic applies here and there.
  18. That seems to have worked. Thanks! I guess as just one more question if I wanted to get multiple variables out of a function or method, I'd just have to make similar lines, except for each variable I'm trying to reference?
  19. sleepy_sealion said:
    if I wanted to get multiple variables out of a function or method
    Well, no. Their scope is local, so you can not get them in any way. Usually, they're only there as a temporary variable to store the value necessary to compute whatever they're computing within the function. What you can get is the return value, not the entire local variable defined in that function. This is true for any programming language as far as I know.

    sleepy_sealion said:
    I'd just have to make similar lines
    You can, but this entirely depends on the scenario. You can make a similar line and it's going to work fine, but some cases may not.

    sleepy_sealion said:
    except for each variable I'm trying to reference?
    I don't understand this sentence.
  20. Sorry if I'm butchering the language. I meant that on top of the value, I could get other things like the targets/items name and stuff like that. But it's really fine if it doesn't work out like that - since I can just think up a generic message for what I'm trying to do.

    Thanks for the help/explanation though.