JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 114 of 171 View original ↗
  1. I'm trying to get a skill to swap out for one of two different skills depending on which two different mutually exclusive state is on a actor. While the new skills show up with the right state the old skill won't disappear. This is the code I'm trying

    Code:
    <Custom Show Eval>
    visible = (!user.isStateAffected(x)) || (!user.isStateAffected(y));
    </Custom Show Eval>

    If I remove the one of the !user.isStateAffected it works but for only that state, what am I doing wrong?
  2. unholywolf said:
    If I remove the one of the !user.isStateAffected it works but for only that state, what am I doing wrong?
    One thing that isn't harmful but is a little wrong because it's unnecessary is the extra parentheses. It's a good habit to only include things like parentheses and braces where you actually need them so that your eyes learn to see what they're grouping.

    The other thing that looks wrong based on your description is the operator you're using. If I understand you correctly, this is the original skill that you want to disappear if either of the states is on the actor.

    You're using the ! NOT operator, which means you're saying "Show this skill if the actor does not have one of these two states".

    Since you also said the states are mutually exclusive, it will always be true that the actor doesn't have one of them.

    It sounds like what you actually want to be checking is if the actor does have one of them, then saying NOT that. So this actually goes really well with what I said above, vis-a-vis the correct use of parentheses :wink:
    Code:
    visible=!(user.isStateAffected(x) || user.isStateAffected(y));

    You could also keep the NOT operators as you originally had them and reverse the middle operator:
    Code:
    visible=!user.isStateAffected(x) && !user.isStateAffected(y);
    e.g. "Show this skill if the actor does not have both of these states"
  3. sleepy_sealion said:
    Thanks for the tips guys! I guess I'll stop trying to use Scene_Base then for everything. For an example though, I was hoping I could use it as an quick way to code out stuff from the same place, Like for example:
    Code:
    Scene_Base.restoreMovementDefaults = function() {
     $gamePlayer._moveSpeed = 4;
     $gamePlayer._through = false;
     $gamePlayer._walkAnime = true;
    };
    Though I guess it would be simpler to just have $gamePlayer call that one in particular.

    I was trying out just having functions that don't belong to an object, but I do remember hearing that it's not ideal. I think I'm just over complicating things again. But I guess the kind of goal was to create a "core" script that I could easily call all these functions and stuff.
    Spoiler
    View attachment 250011

    I misunderstood you. When you said you were calling functions from Scene_Base, I assumed that meant you were calling Scene_Base functions that already exist. Instead, you seem to be extending Scene_Base with your own functions. While there's nothing intrinsically wrong with doing that, it doesn't make any sense in the example that you posted.

    The only time that you should add your own methods to Scene_Base is when both of these are true:
    1. The method specifically has something to do with scenes. Especially if the method is calling other scene methods or accessing fields that belong to a given scene.
    2. You want the method to be inherited by all scenes (since Scene_Base is the parent of all other scenes).
    Since neither of those are true in your example, it doesn't make sense (either technically or organizationally) to put that method in Scene_Base. Instead, I'd personally do one of these two things:

    1. Put it in the Game_Player class:
    JavaScript:
    Game_Player.prototype.restoreMovementDefaults = function() {
        this._moveSpeed = 4;
        this._through = false;
        this._walkAnime = true;
    };

    2. Put it in your own object:
    JavaScript:
    var SeaLion = SeaLion || {};
    
    SeaLion.restorePlayerMovementDefaults = function() {
        $gamePlayer._moveSpeed = 4;
        $gamePlayer._through = false;
        $gamePlayer._walkAnime = true;
    };

    There are some pros and cons to either option, which can kinda vary based on the specific situation.
  4. I'm glad I asked! So right now I'm just testing things not being tied to an object. Though I wasn't aware you could make an object through var like that. For some reason I thought having things not tied to an object would bloat the game - since I remember hearing making a lot of custom $globals could do the same.

    But I guess the reasoning was kind of borked since functions need to be called to run...
  5. sleepy_sealion said:
    For some reason I thought having things not tied to an object would bloat the game - since I remember hearing making a lot of custom $globals could do the same.
    I'm not super sure what that might mean. Data takes up the same amount of disc space/memory whether it's contained within a code object or not.

    Making things global in scope when they don't need to be is bad practice because it increases the odds it might be referenced by accident (or be named the same as something in another plugin, and therefore conflict), but when I see "bloat" that typically references computer resources being used.

    And nothing you do with your custom functions or variables is going to matter on a scale greater than kilobytes unless you start loading image or sound files into memory for no reason.
  6. Is it possible to dynamically change the displayed text of plugin parameters to match values in the database? For example, say I want the name of a parameter to display the name of an element in the Types tab, but I also want that name to be updated if the player changes the corresponding element's name. Is that something the system can do?

    Alternatively, using that same example, is there a way to display other items in an Object Selector aside from the ones listed in this thread? Elements seem to be the only value from the Types tab that aren't present in that list.
  7. Hi, I'm creating a skill that can only be used if a specific actor (ID 5) is alive and is among the first 4 characters active in battle.
    Thanks to Yanfly's plugin "Skill Core" I'm setting the requirements but it doesn't work as it should, what am I doing wrong?
    Here is my code:


    JavaScript:
    <Custom Requirement>
     if ($gameParty.members()[0]._actorId === 5 || $gameParty.members()[1]._actorId === 5 || $gameParty.members()[2]._actorId === 5 || $gameParty.members()[3]._actorId === 5 && !$gameActors.actor(5).isStateAffected(1)) {
       value = true;
     } else {
       value = false;
     }
    </Custom Requirement>
  8. Super015 said:
    Hi, I'm creating a skill that can only be used if a specific actor (ID 5) is alive and is among the first 4 characters active in battle.
    Thanks to Yanfly's plugin "Skill Core" I'm setting the requirements but it doesn't work as it should, what am I doing wrong?
    Here is my code:


    JavaScript:
    <Custom Requirement>
     if ($gameParty.members()[0]._actorId === 5 || $gameParty.members()[1]._actorId === 5 || $gameParty.members()[2]._actorId === 5 || $gameParty.members()[3]._actorId === 5 && !$gameActors.actor(5).isStateAffected(1)) {
       value = true;
     } else {
       value = false;
     }
    </Custom Requirement>
    You're almost there, but you got the operator precedence wrong: think of || like addition and && like multiplication. Your code will check if one of four conditions is true: either the actor is first, or is second, or is third, or is fourth and alive. The fix is fairly simple: put the first part (all the members checks) in parentheses. This will be like turning 1+2+3+4*X into (1+2+3+4)*X.
  9. Mac15001900 said:
    You're almost there, but you got the operator precedence wrong: think of || like addition and && like multiplication. Your code will check if one of four conditions is true: either the actor is first, or is second, or is third, or is fourth and alive. The fix is fairly simple: put the first part (all the members checks) in parentheses. This will be like turning 1+2+3+4*X into (1+2+3+4)*X.
    Thanks, I followed the advice, however the code half works!
    The skill correctly checks if actor 5 is alive or dead but completely ignores if he is among the 4 active battlers, he is marked as always active in any case (even if he is not present in the party).
  10. Super015 said:
    Thanks, I followed the advice, however the code half works!
    The skill correctly checks if actor 5 is alive or dead but completely ignores if he is among the 4 active battlers, he is marked as always active in any case (even if he is not present in the party).

    That will be a bit problematic - my game doesn't have combat, so I'm not very familiar with that part of the codebase. But maybe try using battleMembers() instead of members()? Seems like that's the one meant for getting the members who are in combat.
  11. Super015 said:
    Thanks, I followed the advice, however the code half works!
    The skill correctly checks if actor 5 is alive or dead but completely ignores if he is among the 4 active battlers, he is marked as always active in any case (even if he is not present in the party).
    Can you show us your new code?
  12. Super015 said:
    Thanks, I followed the advice, however the code half works!
    The skill correctly checks if actor 5 is alive or dead but completely ignores if he is among the 4 active battlers, he is marked as always active in any case (even if he is not present in the party).
    You don't need to check the entire party like that 1by1. You should just be able to do:
    if ($gameActors.actor(5).isBattleMember() && $gameActors.actor(5).isStateAffected(1))
  13. Mac15001900 said:
    That will be a bit problematic - my game doesn't have combat, so I'm not very familiar with that part of the codebase. But maybe try using battleMembers() instead of members()? Seems like that's the one meant for getting the members who are in combat.
    Unfortunately that doesn't work either, whether actor 5 is present or not, it always returns true. :kaocry:

    EDIT:

    GmOcean said:
    You don't need to check the entire party like that 1by1. You should just be able to do:
    if ($gameActors.actor(5).isBattleMember() && $gameActors.actor(5).isStateAffected(1))
    Yes, this works! Thank you very much, the problem is solved! :kaojoy:
  14. Is there a way to force a specific SV actor animation to play in place of the default idle via a state?
    For example, make a Charm state that causes a character to use their Victory animation.
    I'm using Yanfly's Buffs & States Core.
  15. Siffers said:
    Is there a way to force a specific SV actor animation to play in place of the default idle via a state?
    For example, make a Charm state that causes a character to use their Victory animation.
    I'm using Yanfly's Buffs & States Core.
    With Yanfly's plugin: "Visual State Effects", you can get the result you want!
  16. Super015 said:
    With Yanfly's plugin: "Visual State Effects", you can get the result you want!
    For some reason, I thought that one was only for playing animations over a sprite.
    Thank you very much!
  17. I'm using Yanfly's State Categories.
    Is there a way to remove a state through an event command instead of a skill/item?
    I saw the JS stuff, but it looked like it was only intended for battle scene use.
  18. Siffers said:
    I'm using Yanfly's State Categories.
    Is there a way to remove a state through an event command instead of a skill/item?
    I saw the JS stuff, but it looked like it was only intended for battle scene use.
    1 - No. It's a pretty short documentation, you can see there are no plugin commands in it :stickytongue:

    2 - You've just misunderstood - Yanfly's use of the term "battler" is simply standing in for any reference to an actor. It does not mean that the code somehow would only function in battle; the code works anyplace you can enter JavaScript.

    Since we don't know anything about the situation you're trying to do this in, we can't actually give you a specific answer, but you can look at the pinned thread of MV script calls to get some different ways to reference actors.

    A few examples are:
    Code:
    $gameActors.actor(5).removeStateCategoryAll("enhancement");
    Removes all states of the category "enhancement" from actor ID 5.

    Code:
    $gameParty.members()[0].removeStateCategory("poison", 2);
    Removes two states of the category "poison" from the first actor in the party.

    Code:
    <Custom Turn End Effect>
    user.removeStateCategory("bleed", 1);
    </Custom Turn End Effect>
    Using Yanfly's Buffs & States Core, this state will remove one state of the category "bleed" at the end of every turn.
  19. ATT_Turan said:
    Since we don't know anything about the situation you're trying to do this in, we can't actually give you a specific answer, but you can look at the pinned thread of MV script calls to get some different ways to reference actors.
    I'm attempting to have a common event that will only remove states within a specific category.
    To be more specific, I'm making a food buff system that applies a state to the whole party for X amount of battles.
    After X reaches zero, it removes the state from the party.
  20. In RMMZ I'm hoping to allow to counter both physical and magic attacks when the character is defending. The way I want it to work is that upon first hit that the affected unit receives (there are a lot of skills that hit multiple times) the defending unit will retaliate with the Counter skill (mainly to increase the counterer's TP but I do realize there are other methods). I have this put in the Defend state's Note are (I am using Visustella):
    <JS Post-Damage as Target> if (this.isHpEffect()) { const skill = 5; const target = -2; user.forceAction(skill, target); } </JS Post-Damage as Target>
    However it's not working as I hope as it causes the enemy that attacks defender to attack the defender continuously until they evade. Sadly my programming skills are very limited.
    As far as I can tell user.forceAction(skill, target); should be altered to something else. Also, note that I do plan to add additional condition for activating the Counter skill, that is to be affected by a state (which AFAIK would be user.isStateAffected(stateID)).