JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 89 of 171 View original ↗
  1. alltheyuriz said:
    @ATT_Turan Permission to read the file ; n ; i don't do anything without permission im sorry
    I don't mean to sound unfriendly, but if you go around asking that you'll likely find more people being annoyed at having to answer an obvious question than being happy to help you learn. There's no such thing legally, morally, or ethically against reading the contents of a file you own.
  2. @ATT_Turan it's okay it's just a bad habit I have adapted
  3. alltheyuriz said:
    I would like to ask some people if they don't mind me looking over their javascripts to help me look more into how to aim it into MV/MZ not using it as a shell or templet just to see functions that work in the script of the program and what not. I would never steal anyone's work

    If I'm correct in reading that you're having trouble figuring out how to interface custom js with rpg maker's engine and wanting clear examples I can relate.

    It's a little open ended, but I'm happy to share the plugin code im working on for mv - though i worry my specific problem space might be too specific to be useful to you. I haven't put it up anywhere properly yet cause i'm not happy with it. My intent is to put anything i do out as a public plugin once I feel like its actually "useable" so don't worry about using whatever you see - I wouldn't consider it stealing.

    High level: I want to be able to walk both over and under bridges, and i want to easily trigger events by walking through regions painted on the map. Happy to explain anything i've done and why if that's helpful.
  4. Hi, i wanted to ask a question to know if what i want to do is possible, i am developing a game as final course project (computer science) so it as a strong focus on programming algoritms like ai, procedural generation and multiplayer (i and three collegues are trying and managing to develop this without use of existing plugins), i wanted to know if its possible for the multiplayer to have a external login system like if you press the multiplayer button with would open a website were you create/login your account sending a post request to a db (mysql) and if the data was valid you would send back the data to the game (maker MV) in a get request, i assume since mv is basicaly web you should be able to make request but i dont know if you can open an external browser and the game enters in a loop waiting for the response, exiting the loop by receiving the info necessary or by you exiting the web page, i know there are existing plugins that have a internal login page (like the online core) but i would prefer doing something here i can rely on html and css if possible.
  5. It would be possible, but afaik there is only one script for multiplayer games, and it's still in development (and I don't recall if it's for MV or one of the earlier engines).

    So now that you know it's possible, if you want to know HOW to do it or where to find this script, please post a new thread in the Plugin Requests forum, as this is definitely not a "question that does not deserve its own thread".
  6. ATT_Turan said:
    1) You're not using the proper name of the function, it's $gameVariables.setValue() and you're missing the dollar sign at the front.
    2) numItems takes a BaseItem as the argument, and $dataWeapons is an array of Weapons, so that won't do anything.

    The problem with what you want to do is that, normally, the engine does not track multiples of weapons and armor in the same way as items. You can see this if you buy a few, open your menu, you'll see, say, four short swords listed individually. So the engine doesn't have a built-in function to say how many of a given weapon the party has, you will have to go through all of their carried weapons and individually add them up.

    First of all, thanks for your help.

    Unfortunately, after using your code, the variable 3 is still locked to 0.

    I think it is because of the Yanfly Item Core plugin activated and the fact that these weapons were considerated as independent items.

    If it is too complicated to resolve, I will find another way.
  7. Boonty said:
    First of all, thanks for your help.

    Unfortunately, after using your code, the variable 3 is still locked to 0.

    I think it is because of the Yanfly Item Core plugin activated and the fact that these weapons were considerated as independent items.

    If it is too complicated to resolve, I will find another way.
    Yes, you should create your own thread about this issue, and make sure you explain in the first post all of the plugins and options that you are using. I believe the Yanfly independent item stuff changes how they're stored in the database.
  8. Is there a way to check what the last skill ID the enemy used via script call?
    I know MZ comes with the ability to check the last skill ID used but this includes skills the party uses as well.
  9. Would someone be able to help me with figuring out how to use arrays with variables?

    In particular, what I'm hoping to achieve is to check if an array contains a string (such as "Swamp"). If it does, then nothing happens, but if it doesn't, that string is added onto the array, and I add 1 to a different variable. Also, I do want this array to be saved even after the save file is reloaded, so from what I understand this array would have to be stored in an actual variable itself, right?
  10. Vis_Mage said:
    check if an array contains a string (such as "Swamp").
    ArrayName.includes("Swamp")
    Vis_Mage said:
    Also, I do want this array to be saved even after the save file is reloaded, so from what I understand this array would have to be stored in an actual variable itself, right?
    Yes...I have seen either threads or plugins that allow you to specify additional data to be saved. Regardless, that's definitely more complex than the scope of this thread, so if you can't find anything Googling it you should post a plugin request.
  11. When the MV Bitmap class's measureTextWidth function is passed something with a bold or italics marker (MSGCORE[1] and MSGCORE[2], respectively), the result makes the text seem a lot wider than it actually is. How would I go about making that function accurately return the width of bolded or italicized text?

    Note that this is for a plugin that measures lines' of text widths one by one, so there needs to be something to detect whether the current line was bolded or italicized based on previous inputs.
  12. Y the heck does this code crash my plugin? I've tried so many things and checked my work over 10 times!!!

    JavaScript:
    // Stat Equations
    // Charm
    var charmNo;
    if ($gameVariables.value(1) <= 60) {
      charmNo = 0;
    } else if ($gameVariables.value(1) > 60 && $gameVariables.value(1) <= 120) {
      charmNo = 1;
    } else if ($gameVariables.value(1) > 120 && $gameVariables.value(1) <= 180) {
      charmNo = 2;
    } else if ($gameVariables.value(1) > 180 && $gameVariables.value(1) <= 240) {
      charmNo = 3;
    } else if ($gameVariables.value(1) > 240 && $gameVariables.value(1) < 300) {
      charmNo = 4;
    } else if ($gameVariables.value(1) >= 300) {
      charmNo = 5;
    }
    
    // Intelligece
    var intNo;
    if ($gameVariables.value(2) <= 60) {
      intNo = 0;
    } else if ($gameVariables.value(2) > 60 && $gameVariables.value(2) <= 120) {
      intNo = 1;
    } else if ($gameVariables.value(2) > 120 && $gameVariables.value(2) <= 180) {
      intNo = 2;
    } else if ($gameVariables.value(2) > 180 && $gameVariables.value(2) <= 240) {
      intNo = 3;
    } else if ($gameVariables.value(2) > 240 && $gameVariables.value(2) < 300) {
      intNo = 4;
    } else if ($gameVariables.value(2) >= 300) {
      intNo = 5;
    }
    
    // Guts
    var gutsNo;
    if ($gameVariables.value(3) <= 60) {
      gutsNo = 0;
    } else if ($gameVariables.value(3) > 60 && $gameVariables.value(3) <= 120) {
      gutsNo = 1;
    } else if ($gameVariables.value(3) > 120 && $gameVariables.value(3) <= 180) {
      gutsNo = 2;
    } else if ($gameVariables.value(3) > 180 && $gameVariables.value(3) <= 240) {
      gutsNo = 3;
    } else if ($gameVariables.value(3) > 240 && $gameVariables.value(3) < 300) {
      gutsNo = 4;
    } else if ($gameVariables.value(3) >= 300) {
      gutsNo = 5;
    }
    
    // Athletics
    var athNo;
    if ($gameVariables.value(4) <= 60) {
      athNo = 0;
    } else if ($gameVariables.value(4) > 60 && $gameVariables.value(4) <= 120) {
      athNo = 1;
    } else if ($gameVariables.value(4) > 120 && $gameVariables.value(4) <= 180) {
      athNo = 2;
    } else if ($gameVariables.value(4) > 180 && $gameVariables.value(4) <= 240) {
      athNo = 3;
    } else if ($gameVariables.value(4) > 240 && $gameVariables.value(4) < 300) {
      athNo = 4;
    } else if ($gameVariables.value(4) >= 300) {
      athNo = 5;
    }
  13. NateThe8 said:
    Y the heck does this code crash my plugin? I've tried so many things and checked my work over 10 times!!!
    What is the larger function that this is inside of? Just putting this into a js file that you install as a plugin is going to make it try to run when you start up the program, and there are no gameVariables until you actually get past the title screen into the game. This needs to be encapsulated inside of a function (getCharm, etc.) that you then call at a specific time from inside your game to get that value. That could be causing your crash.
    NateThe8 said:
    JavaScript:
    if ($gameVariables.value(1) <= 60) {
      charmNo = 0;
    } else if ($gameVariables.value(1) > 60 && $gameVariables.value(1) <= 120) {
    Just to point it out, this (and the entire rest of your code where you do the same thing) is wasteful. Logically, if you have gotten past your first "if" to be seeing this "else," the value must be higher than 60, so there's no point in checking that again - you only care now whether it's <= 120.

    Yes, the effect on your CPU is negligible, but it's still wasted work, and wasted typing on your part.
    NateThe8 said:
    Code:
    } else if ($gameVariables.value(1) >= 300) {
    Same thing here, by the time you get this far the value has to be >= 300, so why bother calling the function? Just say "else".

    Finally, if/else statements automatically apply to the one following command, so if you only have one command inside of each one, there's no reason for you to bother typing braces around it.
    NateThe8 said:
    // Intelligece
    There's something funny to say about misspelling "intelligence" :wink:
  14. ATT_Turan said:
    What is the larger function that this is inside of? Just putting this into a js file that you install as a plugin is going to make it try to run when you start up the program, and there are no gameVariables until you actually get past the title screen into the game. This needs to be encapsulated inside of a function (getCharm, etc.) that you then call at a specific time from inside your game to get that value. That could be causing your crash.

    Just to point it out, this (and the entire rest of your code where you do the same thing) is wasteful. Logically, if you have gotten past your first "if" to be seeing this "else," the value must be higher than 60, so there's no point in checking that again - you only care now whether it's <= 120.

    Yes, the effect on your CPU is negligible, but it's still wasted work, and wasted typing on your part.

    Same thing here, by the time you get this far the value has to be >= 300, so why bother calling the function? Just say "else".

    Finally, if/else statements automatically apply to the one following command, so if you only have one command inside of each one, there's no reason for you to bother typing braces around it.

    There's something funny to say about misspelling "intelligence" :wink:
    I threw it inside of a function, but that didn't seem to work very well. The full function is a modified Polygon Stat Plugin that was modified to work with Yanfly Extra Status Menu pages.

    JavaScript:
    if (Imported.YEP_StatusMenuCore) {
    Window_StatusInfo.prototype.drawSocialPageContent = function() {
        var dx = indent;
        var dy = this.lineHeight() / 2;
        var dw = this.contents.width - indent;
        var dh = this.lineHeight();
        var dw2;
        var text;
      // Stat Equations
      // Charm
      var charmNo;
      if ($gameVariables.value(1) <= 60) {
        charmNo = 0;
      } else if ($gameVariables.value(1) > 60 && $gameVariables.value(1) <= 120) {
        charmNo = 1;
      } else if ($gameVariables.value(1) > 120 && $gameVariables.value(1) <= 180) {
        charmNo = 2;
      } else if ($gameVariables.value(1) > 180 && $gameVariables.value(1) <= 240) {
        charmNo = 3;
      } else if ($gameVariables.value(1) > 240 && $gameVariables.value(1) < 300) {
        charmNo = 4;
      } else if ($gameVariables.value(1) >= 300) {
        charmNo = 5;
      }
    
      // Intelligece
      var intNo;
      if ($gameVariables.value(2) <= 60) {
        intNo = 0;
      } else if ($gameVariables.value(2) > 60 && $gameVariables.value(2) <= 120) {
        intNo = 1;
      } else if ($gameVariables.value(2) > 120 && $gameVariables.value(2) <= 180) {
        intNo = 2;
      } else if ($gameVariables.value(2) > 180 && $gameVariables.value(2) <= 240) {
        intNo = 3;
      } else if ($gameVariables.value(2) > 240 && $gameVariables.value(2) < 300) {
        intNo = 4;
      } else if ($gameVariables.value(2) >= 300) {
        intNo = 5;
      }
    
      // Guts
      var gutsNo;
      if ($gameVariables.value(3) <= 60) {
        gutsNo = 0;
      } else if ($gameVariables.value(3) > 60 && $gameVariables.value(3) <= 120) {
        gutsNo = 1;
      } else if ($gameVariables.value(3) > 120 && $gameVariables.value(3) <= 180) {
        gutsNo = 2;
      } else if ($gameVariables.value(3) > 180 && $gameVariables.value(3) <= 240) {
        gutsNo = 3;
      } else if ($gameVariables.value(3) > 240 && $gameVariables.value(3) < 300) {
        gutsNo = 4;
      } else if ($gameVariables.value(3) >= 300) {
        gutsNo = 5;
      }
    
      // Athletics
      var athNo;
      if ($gameVariables.value(4) <= 60) {
        athNo = 0;
      } else if ($gameVariables.value(4) > 60 && $gameVariables.value(4) <= 120) {
        athNo = 1;
      } else if ($gameVariables.value(4) > 120 && $gameVariables.value(4) <= 180) {
        athNo = 2;
      } else if ($gameVariables.value(4) > 180 && $gameVariables.value(4) <= 240) {
        athNo = 3;
      } else if ($gameVariables.value(4) > 240 && $gameVariables.value(4) < 300) {
        athNo = 4;
      } else if ($gameVariables.value(4) >= 300) {
        athNo = 5;
      }
      // Social Stat Text
    /*    this.changeTextColor(this.systemColor());
        this.drawText("Charm: " + charm[c], dx, dy, dw, 'center');
      this.drawText("Intelligence: " + intelligece[in], dx, dy, dw, 'center');
      this.drawText("Guts: " + guts[g], dx, dy, dw, 'center');
      this.drawText("Athletics: " + athletics[at], dx, dy, dw, 'center'); */
        dy = this.lineHeight();
        dx = indent;
        dw -= this.standardPadding() * 2;
    /*    for (var i = 2; i < 8; ++i) {
            dy += this.lineHeight();
            var rate = this.drawParamGauge(dx, dy, dw, i);
            this.changeTextColor(this.systemColor());
            this.drawText(TextManager.param(i), dx + 4, dy, dw - 4);
            text = Yanfly.Util.toGroup(this._actor.param(i))
            this.changeTextColor(this.normalColor());
            dw2 = dw * rate;
            this.drawText(text, dx, dy, dw2 - 4, 'right');
        }*/
    
        this.contents.SPolyDrawStatPolygon(this._actor);
    
        //draw text
        if (useText) {
            this.changeTextColor(textColor);
            this.contents.fontSize = this.standardFontSize() - fontDecrement;
            for (var i = 0; i < 4; i++) {
                this.drawText(social[i], centerX + customOff[i] + (radius + textOffset.radial) * Math.cos(Math.PI/2 + i * 2 * Math.PI / sides), centerY + textOffset.y - (radius + textOffset.radial) * Math.sin(Math.PI/2 + i * 2 * Math.PI / sides), 160);
            }
            this.resetFontSettings();
        }
    
        //draw icon
        if (useIcon) {
            for (var i = 0; i < stats.length; i++) {
                this.drawIcon(iconIndexes[i], centerX + iconOffset.x + (radius + iconOffset.radial) * Math.cos(Math.PI/2 + i * 2 * Math.PI / sides), centerY + iconOffset.y - (radius + iconOffset.radial) * Math.sin(Math.PI/2 + i * 2 * Math.PI / sides));
            }
        }
    };
    }
  15. @NateThe8 So what happens when you try to display that window? I suggest you split this out and post as its own thread for help.
  16. ATT_Turan said:
    @NateThe8 So what happens when you try to display that window? I suggest you split this out and post as its own thread for help.
    i ended up fixing it my making a seperate function just for it but weird how it doesnt work inside that function
  17. NateThe8 said:
    i ended up fixing it my making a seperate function just for it but weird how it doesnt work inside that function
    I mean, I don't see you use those variables for anything in the function you wrote, so I don't know what you're trying to accomplish...but I'm glad you got something working for yourself.
  18. I decided to replace all the if & else if statements for the stats with something simpler, hope you don't mind :)
    const parseValue = function(val) { return val < 1 ? 0 : val < 300 ? Math.trunc((val - 1) / 60) : 5; // NOTE: This is how the above line works: // if (val < 1) { // return 0; // } else if (val < 300) {// Are you sure it should be less than 300? val <= 300 would have been more logical. // return Math.trunc((val - 1) / 60); // // 1. Subtract 1 from val // // 2. Split the value by 60 // // 3. finally use Math.trunc() to remove any decimals // } else { // return 5; // } }; // Charm var charmNo = parseValue($gameVariables.value(1)); // Intelligence var intNo = parseValue($gameVariables.value(2)); // Guts var gutsNo = parseValue($gameVariables.value(3)); // Athletics var athNo = parseValue($gameVariables.value(4));

    Edit: BTW.. Charm, Intelligence, Guts & Athletics? Do I smell a fellow Persona fan? :)
  19. WaCrex said:
    I decided to replace all the if & else if statements for the stats with something simpler, hope you don't mind :)
    const parseValue = function(val) { return val < 1 ? 0 : val < 300 ? Math.trunc((val - 1) / 60) : 5; // NOTE: This is how the above line works: // if (val < 1) { // return 0; // } else if (val < 300) {// Are you sure it should be less than 300? val <= 300 would have been more logical. // return Math.trunc((val - 1) / 60); // // 1. Subtract 1 from val // // 2. Split the value by 60 // // 3. finally use Math.trunc() to remove any decimals // } else { // return 5; // } }; // Charm var charmNo = parseValue($gameVariables.value(1)); // Intelligence var intNo = parseValue($gameVariables.value(2)); // Guts var gutsNo = parseValue($gameVariables.value(3)); // Athletics var athNo = parseValue($gameVariables.value(4));

    Edit: BTW.. Charm, Intelligence, Guts & Athletics? Do I smell a fellow Persona fan? :)
    well that sure saved me some lines thx and about that Persona game...
  20. This seems like an easy enough question, but I can't find a definitive answer. I want to expand the existing JSON data files with additional fields, to hold additional information about attacks, skills, states, etc., however they are being overwritten immediately on the next save.
    I do have an idea about creating additional "extension" databases and merging them on load, but it seems like a lot of hassle for something so basic. I feel like there should be a simpler answer for what I'm looking for. My current use case is adding additional message fields to States, so every player character gets a different message when they're hit with the same effect.