JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 71 of 171 View original ↗
  1. Lanzy said:
    I assume newSprite.scale.x = 1 is 100% size and then 2 would be 200% and so on? And that I need to do before adding the Sprite as a Child or could it also be done after?
    Hi!
    Yes, 1 means 100%, so 0.70 should mean 70%.
    I think you can do it after or before add the child :)
  2. Eliaquim said:
    Hi!
    Yes, 1 means 100%, so 0.70 should mean 70%.
    I think you can do it after or before add the child :)

    This opens up so many possibilities. Thank you very much :)
  3. Hello, I'm trying to set up a skill's targeting that's more advanced than anything I've done before. Here's how it should work:
    If the enemy getting hovered over is isn't affected by a certain state:
    The skill will affect that enemy only.
    Otherwise,
    The skill will affect every enemy in the row of the one getting hovered over.
    I've got the different effects covered in the damage formula.

    The relevant plugins for the situation are installed and set up: Target Core, Selection Control, and Row Formation. All 3 by Yanfly.
    The issue is that I have no idea how to make it happen, I know how to define eligible targets but not some sort of AoE depending on the state of an enemy that's getting hovered over. Can somebody help me with that?
  4. CHKNRAVE said:
    Hello, I'm trying to set up a skill's targeting that's more advanced than anything I've done before. Here's how it should work:
    If the enemy getting hovered over is affected by a certain state:
    The skill will affect that enemy only.
    Otherwise,
    The skill will affect every enemy in the row of the one getting hovered over.
    I've got the different effects covered in the damage formula.

    The relevant plugins for the situation are installed and set up: Target Core, Selection Control, and Row Formation. All 3 by Yanfly.
    The issue is that I have no idea how to make it happen, I know how to define eligible targets but not some sort of AoE depending on the state of an enemy that's getting hovered over. Can somebody help me with that?

    I don't have Row Formation so I can't see the exact syntax for targeting an enemy row, but basically what you need to do is a Custom Target Eval:

    Code:
    <Custom Target Eval>
      if (!target.isStateAffected(id of state you're checking for)) {
        // target entire row
      }
    </Custom Target Eval>
  5. I think I'm onto something, however my formula needs some extra work so the effect if the target has the state is applied to the entire row.

    Here's what worked:
    Code:
    <Custom Target Eval>
    if (target.isStateAffected(16)) {
      for (var i = 0; i < foes.aliveMembers().length; ++i) {
        var member = foes.aliveMembers()[i];
        if (member.row === target.row) targets.push(member);
      }
    } else {
      targets.push(target);
    }
    </Custom Target Eval>
  6. You forgot the ! !target.isStateAffected(16)

    You said you only wanted it to target the entire row if they *didn't* have that state, right?
  7. My bad, what I really wanted was to target the whole row if the enemy getting hovered over does have the state.
  8. How do I write to a file in a browser-friendly way? I know how to use XMLHTTPRequest to read a file, but all the solutions I found for writing require either...

    - Using a server-side language like PHP
    - Having some input element in the html file

    Is there some way I can just use JS for this, without messing with the DOM or trying to find some hack that uses another language?
  9. CG-Tespy said:
    How do I write to a file in a browser-friendly way? I know how to use XMLHTTPRequest to read a file, but all the solutions I found for writing require either...

    - Using a server-side language like PHP
    - Having some input element in the html file

    Is there some way I can just use JS for this, without messing with the DOM or trying to find some hack that uses another language?
    You can't write actual files when playing in the browser, you can only store data in the browser itself. And using a server language like php would write the files on the server, not on the player's pc.
  10. To my understanding, XMLHttpRequests are requests for servers to do things. Since I managed to use them to read files on disk, I assume that MV has the game's directory treated as server storage. Or is there something else that explains the following code working?

    JavaScript:
    let req = new XMLHttpRequest();
    req.open("GET", path, false); // path is relative to the game's index.html file
    req.send();
    return req.responseText; // the file's contents

    If I misunderstood, then would that mean that it's impossible to write to files on disk without breaking browser compatibility?
  11. Hi I'm trying to figure out what this method of the "Window_Selectable" class is trying to return.
    What exactly does "topIndex" mean and how can it be useful?
    JavaScript:
    Window_Selectable.prototype.topIndex = function () {
      return this.topRow() * this.maxCols();
    };

    So "maxCols()" returns the maximum number of columns of course, but I don't really understand what "topRow()" means.

    JavaScript:
    Window_Selectable.prototype.topRow = function () {
      return Math.floor(this._scrollY / this.itemHeight());
    };
  12. CG-Tespy said:
    To my understanding, XMLHttpRequests are requests for servers to do things. Since I managed to use them to read files on disk, I assume that MV has the game's directory treated as server storage. Or is there something else that explains the following code working?

    JavaScript:
    let req = new XMLHttpRequest();
    req.open("GET", path, false); // path is relative to the game's index.html file
    req.send();
    return req.responseText; // the file's contents

    XMLHttpRequests can read files because the browser can read files using the file:// protocol, but there's no way for browsers to write files on the user's disk.

    CG-Tespy said:
    If I misunderstood, then would that mean that it's impossible to write to files on disk without breaking browser compatibility?
    That's correct, but you can still save data to the user's browser (the game saves, for example). You just can't save files.

    meowengine said:
    Hi I'm trying to figure out what this method of the "Window_Selectable" class is trying to return.
    What exactly does "topIndex" mean and how can it be useful?
    JavaScript:
    Window_Selectable.prototype.topIndex = function () {
      return this.topRow() * this.maxCols();
    };

    So "maxCols()" returns the maximum number of columns of course, but I don't really understand what "topRow()" means.

    JavaScript:
    Window_Selectable.prototype.topRow = function () {
      return Math.floor(this._scrollY / this.itemHeight());
    };

    topRow returns the first visible row on the window. When you scroll down a selectable window the topRow index will increase as more rows are hidden by the scroll.
  13. I'm trying to read the system clock's date for events that happen in my game that are restricted to certain dates in the real world. Is there a way to check what the current date is and if it matches the date I want it to be, to cause a switch to activate?
  14. 1594207588547.png

    Code:
    $gameVariables.setValue(1, new Date().toLocaleDateString());
  15. Trihan said:
    View attachment 150560

    Code:
    $gameVariables.setValue(1, new Date().toLocaleDateString());
    So, does this store the date as 782020 in variable 1? Is there a way to leave the year out, by chance?
  16. Yeah, you can format the date basically any way you want. It's stored as "7/8/2020" in the variable; when you store a string in a variable and display it in a show text command it'll show exactly as it's stored. But the Date object has many functions for getting the individual parts of it.
  17. Hudell said:
    That's correct, but you can still save data to the user's browser (the game saves, for example). You just can't save files.

    Ah, alright. Thanks for the answer :) Good thing MV supports the HTML Web Storage API, which is what you use to save to the browser. I'll leave a link here, in case someone else has the same problem I did.
  18. Trihan said:
    Yeah, you can format the date basically any way you want. It's stored as "7/8/2020" in the variable; when you store a string in a variable and display it in a show text command it'll show exactly as it's stored. But the Date object has many functions for getting the individual parts of it.
    So, exactly how would I leave off the year? Or can you lead me to a resource that can give me some more info? Alternatively, is there a way to cut off the last 4 digits of a variable? Because that would also work, although I can't find anything like that. I tried dividing it by 10,000 to change the decimal point but it seems like trying to do anything to the variable will just set it back to 0 since it has "/" in it.
  19. If you just want the date and month:

    Code:
    let date = new Date();
    
    $gameVariables.setValue(1, date.getDate() + "/" + (date.getMonth() + 1));

    Or the other way round if you want US date format.
  20. Trihan said:
    If you just want the date and month:

    Code:
    let date = new Date();
    
    $gameVariables.setValue(1, date.getDate() + "/" + (date.getMonth() + 1));

    Or the other way round if you want US date format.
    Ah I was fiddling around with it and all I missed was that first line. Good to know, thanks for your help!