JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 144 of 171 View original ↗
  1. Also:
    1. AquaEcho said:
      JavaScript:
      if([AErewindLog[0][0]]<0){
      Why not just if (AErewindLog[0][0] < 0) {? I just tested and it seems to work out to the same result: I imagine the array gets cast to a number in order to compare values. But it's unnecessary.
      [Edit: corrected AErewind to AErewindLog, but you got the idea. :kaoslp:]

    2. AquaEcho said:
      JavaScript:
      this.character[AErewindLog[0][0]]
      Are you sure you didn't mean this.character(AErewindLog[0][0]) here? By default Game_Interpreter#character is a function that returns $gamePlayer when given a negative character ID.
  2. This is a two part question regarding Yanfly's action sequence plugins.

    1)

    Okay, so there's several similarly named action sequences in the action sequence pack and I'm not sure I understand what the difference is between them, so I'm going to post the ones I'm confused about.

    What's the difference between these three?

    perform action - character steps forward and does their motion (swing if attack, etc)
    attack animation: target (same? What's difference between this and last?)
    motion attack: target (does the motion for the attack? Again what is different from above two.

    And what's the difference between these three?

    animation wait: x
    wait: frames
    wait: animation

    2)

    Which would I use if I'm using a skill that does the same attack animation (swinging weapon) twice in a row? and how would I implement it? I've been trying to get a sequence to work but they only seem to do the attack motion once.
  3. Just for reference, none of these involve JavaScript, so this would really belong in its own thread in Plugin Support (or one of the action sequence threads).

    PersistentDreamerGames said:
    What's the difference between these three?

    perform action - character steps forward and does their motion (swing if attack, etc)
    What it says. This is what you see in the default battle in MV, they step forward and swing.

    PersistentDreamerGames said:
    attack animation: target (same? What's difference between this and last?)
    The actual description from the documentation for reference:
    1714517346343.png

    Thus:
    1714517382251.png

    This has nothing to do with the battler moving or using any motion, so you'll have to describe what part you're confused about.

    PersistentDreamerGames said:
    motion attack: target (does the motion for the attack? Again what is different from above two.
    It is completely different from playing an animation.

    It is similar to perform action, except you'll see it doesn't say that the battler steps forward first.

    It also allows you to specify which battler is performing the motion, which perform action does not do.

    PersistentDreamerGames said:
    animation wait: x
    wait: frames
    Again, this description seems quite clear to me in the documentation.
    1714517583125.png

    Therefore, wait: 4 is not the same as animation wait: 4

    If you wanted to time something to happen at a specific frame in the animation, the animation wait command is provided so you don't need to do multiplication to convert animation frames to game frames.

    PersistentDreamerGames said:
    wait: animation
    That's not a valid action sequence command, but I assume you mean wait for animation - again, the description seems clear. You'll need to specify which part of the wording you don't understand.
    1714517726092.png

    PersistentDreamerGames said:
    Which would I use if I'm using a skill that does the same attack animation (swinging weapon) twice in a row?
    Okay, this gives a bit of a clue about the first part. You seem to be confusing two very different terms.

    An animation is a spritesheet defined in the Animations tab of your database.

    The pictures on an SV battler's spritesheet that make them look like they're walking or swinging a weapon are not animations, they're called motions.

    If you just want to swing the weapon twice, you would do:
    Code:
    motion attack: user
    wait: 36
    motion attack: user

    If you want to show those attacks hitting the target, then you'd insert action effect, action animation, etc. (in which case you could get rid of the wait: 36 and use wait for animation)
  4. Sorry for the late response, my PC was acting up and not saving files because apparently the project was on One Drive which was full.

    Arthran said:
    Does ATT_Turan's syntax correction resolve this question for you, or do need further assistance with it?
    Yes, his syntax correction fixed the second issue
    caethyril said:
    Are you sure you didn't mean this.character(AErewindLog[0][0]) here? By default Game_Interpreter#character is a function that returns $gamePlayer when given a negative character ID.
    Yes, I was typing it off of memory since I was unable to test the function due to the aforementioned syntax issue.
  5. ATT_Turan said:
    Just for reference, none of these involve JavaScript, so this would really belong in its own thread in Plugin Support (or one of the action sequence threads).
    Whoops! I figured since it was under Javascript / Plugins that it would be okay and didn't want to waste a thread on this. Thanks for the correction for next time I suppose.
    ATT_Turan said:
    The actual description from the documentation for reference:
    1714517346343.png

    Thus:
    1714517382251.png

    This has nothing to do with the battler moving or using any motion, so you'll have to describe what part you're confused about.
    So that's actually not the one I was asking about.This is the one I was looking at, under action sequence pack 2. I wasn't actually confused about the ones that do animations on the user. I just saw three different ones that did attack animation and wasn't really clear on the difference between them. How is this one different from motion attack: target. Is it just the determined by actor's weapon thing?
    1714519362879.png
    ATT_Turan said:
    It is similar to perform action, except you'll see it doesn't say that the battler steps forward first.

    It also allows you to specify which battler is performing the motion, which perform action does not do.
    That's what I was looking for with that one. Got it. You're right wait ones are self explanatory, I just let the similar wording throw me off I think.
  6. PersistentDreamerGames said:
    So that's actually not the one I was asking about.This is the one I was looking at, under action sequence pack 2. I wasn't actually confused about the ones that do animations on the user. I just saw three different ones that did attack animation and wasn't really clear on the difference between them. How is this one different from motion attack: target. Is it just the determined by actor's weapon thing?
    It's entirely different - you still seem to be mixing up the same thing :stickytongue:

    motion attack will make the battler perform their attack motion - the little chibi looks like it's swinging a sword or whatever. That is not an animation.

    attack animation plays the animation set on the weapon. That is not a motion.
    1714520122828.png
  7. ATT_Turan said:
    It's entirely different - you still seem to be mixing up the same thing :stickytongue:

    motion attack will make the battler perform their attack motion - the little chibi looks like it's swinging a sword or whatever. That is not an animation.

    attack animation plays the animation set on the weapon. That is not a motion.
    View attachment 303664
    Oh! That is what was throwing me off. Okay, so the difference between attack: animation and action: animation then is that attack: animation uses the weapon of the character to determine the animation and action: animation just goes off what shows in the skill.

    Well thank you for the lightbulb moment. So if I'm doing a double attack, MOTION is the one that matters.
  8. What is the best way to monitor a set of variables and switches for changes on a map? I got the move backwards part working on my rewind plugin but I wanted to do something like a map note where the user defines a set of switches in a map, e.g. <mapSwitches: 3, 5, 10>, then append a script to an engine method so every time a switch is toggled, to check if it's one of those numbers, push that switch number into the AErewindLog array.
  9. AquaEcho said:
    append a script to an engine method so every time a switch is toggled, to check if it's one of those numbers
    Wouldn't you just do that?

    You go to Game_Switches.setValue() and do something like
    Code:
    if ($dataMap.meta.mapSwitches && $dataMap.meta.mapSwitches.includes(switchId))

    Maybe I don't get where/how else you would need to monitor it.

    You might want to do something in the DataManager to convert the metatag string into an array of values so you don't get a false match between, say, 8 and 82.
  10. In RMMV, is there any way to make the screen shake not affect pictures drawn with the Show Picture command? It's super distracting to see a character's bust image shaking as if it were tied directly to the map.
  11. @Prescott - you'd need a plugin, e.g. something to counter-offset (specific) pictures. By default screen shake offsets the spriteset, and pictures are a part of that.
  12. I'm trying to have a custom function push and force a moveroute of the event calling the function, but am starting to feel lost in a swamp... Basically a function in which you specify the target event, the starting index of animation, the total number of frames, and the interval between frames. The latest is that it says that "step is not defined".

    Any help greatly appreciated... (yes I do realize I should not have ventured into interpreter territory...)

    EDIT: so after a lot of experimenting, I think I got it... it's very verbose, will minimize later but it works.

    JavaScript:
    function animateTwelve(target, start, length, interval) {
        let evId;
        if(typeof(target) == "number"){
        evId = target;
        } else if(typeof(target) == "object"){
        evId = target._eventId;
        }
        let list = [];
        let step = start;
        for (step = start; step < length; step++){
        /* frames assumed to be in the following order on the spritesheet:
        0  7  8
        1  6  9
        2  5  10
        3  4  11
         */
    
        if (step >>> 2 == 0) {
        list.push({code:(step % 4 + 16),parameters: []});
        list.push({code:45,parameters: ["this._pattern = 0"]});
        list.push({code:45,parameters: ["this._originalPattern = 0"]});
        } else if (step >>> 2 == 1) {
        list.push({code:(3 - (step % 4) + 16),parameters: []});
        list.push({code:45,parameters: ["this._pattern = 1"]});
        list.push({code:45,parameters: ["this._originalPattern = 1"]});
        } else if (step >>> 2 == 2) {
        list.push({code:(step % 4 + 16),parameters: []});
        list.push({code:45,parameters: ["this._pattern = 2"]});
        list.push({code:45,parameters: ["this._originalPattern = 2"]});
        }
        list.push({code:15, parameters: [interval]});  
        console.log("_step:" + step + "_pattern:" + (step >>> 2) + "_direction:" + ((step % 4 + 1) * 2) + "_interval:" + interval);
        }
    
        list.push({code:0, parameters: []});
        let moveRoute = {list: list,repeat:false, skippable: true, wait: true}
        $gameMap.event(evId).forceMoveRoute(moveRoute);
        $gameMap._interpreter.setWaitMode("route");
           
    }

    Initial attempt
    JavaScript:
    function animateTwelve(target, start, length, interval) {
        let evId;
        if(typeof(target) == "number"){
        evId = target;
        } else if(typeof(target) == "object"){
        evId = target._eventId;
        }
        let list = [];
        for (let step = start; step < length; step++){
     
        list.push({code:(step % 4 + 1),parameters: []});
        $gameMap._events[evId]._originalPattern = step >>> 2;
        $gameMap._events[evId]._direction = (step % 4 + 1) * 2;
        list.push({code:15, parameters: [interval]});
        }
    
        console.log("_step:" + step + "_pattern:" + (step >>> 2) + "_direction:" + ((step % 4 + 1) * 2) + "_interval:" + interval);
    
        list.push({code:0, parameters: []});
        let moveRoute = {list: list,repeat:false, skippable: true, wait: true}
        $gameMap.event(evId).forceMoveRoute(moveRoute);
        $gameMap._interpreter.setWaitMode("route");
    }
  13. @werzaque
    suggestions
    1. You set the main interpreter (i.e. non-Parallel) to wait for the movement, but you do not give it a reference character.

      • MV stores a reference to the wait character; MZ stores only its ID. Full examples can be found on the MV / MZ Script Call List (you can open it in Google Sheets and Ctrl+F for Set Movement Route).

      • It would be better if you had an interpreter reference instead, e.g. as an argument of your animateTwelve function:
        JavaScript:
        function animateTwelve(target, start, length, interval, interpreter) {
          //...
          if (interpreter) {
            interpreter._characterId = evId;  // assume MZ
            interpreter.setWaitMode("route");
          }
        }

    2. You can rewrite stuff like this:
      JavaScript:
          list.push({code:45,parameters: ["this._pattern = 0"]});
          list.push({code:45,parameters: ["this._originalPattern = 0"]});
      ...as:
      JavaScript:
          list.push({
              code: Game_Character.ROUTE_SCRIPT,
              parameters: ["this._originalPattern = 0; this.resetPattern();"]
          });
      Reasoning:
      • By default only 1 move command is processed per route, per mechanical frame.
      • It's best practise to use accessor methods, e.g. resetPattern, where available. Especially if using other plugins.
      • Game_Character.ROUTE_SCRIPT is more readable than 45.

    3. Since the route is the same every time, you might consider generating it once, when the plugin loads. Then animateTwelve would just give that route to a character (and proc the interpreter wait mode if apt).

    4. You can use this.character(evId) instead of $gameMap.event(evId): the former is the usual method, and supports additional values, notably 0 for This Event (with a safety check to avoid referencing a different event if the map has changed since the event started).

    5. let list can be const list because you never reassign it.

    6. typeof(value) can be written as typeof value if you like.
  14. Thank you! I follow most of the things you suggest, but the interpreter part has me puzzled:
    caethyril said:
    function animateTwelve(target, start, length, interval, interpreter) {
    //...
    if (interpreter) {
    interpreter._characterId = evId; // assume MZ
    interpreter.setWaitMode("route"); } }
    What is expected to be fed into this when calling the function? For the four-argument function in my initial scribblings, a 12-frame animation would look like: animateTwelve(this, 0, 12, 20).

    EDIT: in any case, have tried to slim it down some. So far seems to work for both 12 frame and 10 frame doors.

    Attempt 3 or 4
    JavaScript:
    function animateTwelve(target, start, length, interval) {
        let evId;
        if(typeof(target) == "number"){
        evId = target;
        } else if(typeof(target) == "object"){
        evId = target._eventId;
        }
        let list = [];
        let step = start;
        let patParam;
        for (step = start; step < length; step++){
    
        if ((step >>> 2) % 2 == 0) {
        list.push({code:(step % 4 + 16),parameters: []});
        } else if ((step >>> 2) % 2 == 1) {
        list.push({code:(3 - (step % 4) + 16),parameters: []});
        }
        patParam= ["this._originalPattern = " + (step >>> 2) + "; this.resetPattern();"];
    //code 45 is ROUTE_SCRIPT
        list.push({code:45,parameters: patParam});
        console.log(patParam);
    //insert wait equal to interval
        list.push({code:15, parameters: [interval]});   
        
        }
    
        list.push({code:0, parameters: []});
        let moveRoute = {list: list,repeat:false, skippable: true, wait: true}
        $gameMap.event(evId).forceMoveRoute(moveRoute);
        $gameMap._interpreter.setWaitMode("route");
        console.log(list);   
        
    }
  15. Hey, I'd like an MZ version of this script so I can show Class name in dialogue :3

    dfsd.png
  16. $gameActors.actor(x).currentClass().name gets you that
  17. werzaque said:
    Thank you! I follow most of the things you suggest, but the interpreter part has me puzzled:
    What is expected to be fed into this when calling the function?
    An interpreter :wink:

    So if you're calling it from a Script event command, you'd do
    Code:
    animateTwelve(42, 3, 9, this);

    Then you have a reference to an interpreter to use the built-in methods on.
  18. ATT_Turan said:
    Then you have a reference to an interpreter to use the built-in methods on.
    Okay, so in the above example it would be

    animateTwelve(this,0,12,20,this)

    Because the event and the interpreter both happen to be, errr, this…?
  19. werzaque said:
    What is expected to be fed into this when calling the function? For the four-argument function in my initial scribblings, a 12-frame animation would look like: animateTwelve(this, 0, 12, 20).
    If you're using it in a move route, or somewhere else with no specific event interpreter, that's more awkward.

    If you call it from a "normal" Script command, or bind it to a Plugin Command, you would be able to pass this, like Turan suggests. E.g. animateTwelve(0, 0, 12, 20, this);.

    Alternatively you could either:
    • Explicitly call it in an interpreter context (animateTwelve.call(this, 0, 0, 12, 20)); or
    • Define it as an interpreter method (Game_Interpreter.prototype.animateTwelve) then invoke, e.g. this.animateTwelve(0, 0, 12, 20).
    In either of these cases, you'd just refer to the interpreter as this in the code of your animateTwelve function.

    I think setting a wait mode on an interpreter when it is not running would just cause the wait to fail. I've done tests on it before but I don't recall the specifics.

    Edit:
    werzaque said:
    Okay, so in the above example it would be

    animateTwelve(this,0,12,20,this)
    No: an event and an interpreter are two different things.
  20. werzaque said:
    Okay, so in the above example it would be
    Sorry, I don't see an example of how you're using it in your project, but no. An object can never be two types; it's either an event or an interpreter (or, obviously, something entirely else :stickytongue: ).

    The only way that could ever be relevant is if you were referring to some inherited properties. For example, a Game_Actor object can also refer to things it inherited from Game_BattlerBase.