JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 81 of 171 View original ↗
  1. Lanzy said:
    I wasn't sure if you wanted to have the 20% chance every time MP is used or just outright 20% chance
    regardless of MP use. So I did both.

    Thank you very much, everything works great!

    Just as an extra question, what would be the line of code I could add to play a SE?
  2. Vis_Mage said:
    Thank you very much, everything works great!

    Just as an extra question, what would be the line of code I could add to play a SE?

    First off: Just realized u wanted a probability of 10% not 20%. Simply change the line where it says

    if (Math.random() <= 0.2)

    To

    if (Math.random() <= 0.1)

    Secondly:
    I attached an excel sheet with script calls you can use in MV. There are a lot of useful methods in there.
    Amongst them you will find sound effects too.

    Cheers
  3. Bit of an odd question here. I've been using a script call to check whether certain party members have a certain accessory equipped. This is the script that I'm using in the conditional branch. (Note: I'm checking equip slot 4 and 5 due to using Yanfly's Equip Core to allow for two accessory slots)

    Code:
    $gameParty.members()[2].equips()[4].id === 67 || $gameParty.members()[2].equips()[5].id === 67

    The thing is, this works perfectly in game. The only oddity is, if this check returns false, I get the following error in the console. (Also, just to note, even though EventCopier shows up in the error, disabling it gives the same error)

    Capture.PNG

    Could someone help me tweak my script to fix the errors showing up in the console?
  4. Vis_Mage said:
    Bit of an odd question here. I've been using a script call to check whether certain party members have a certain accessory equipped. This is the script that I'm using in the conditional branch. (Note: I'm checking equip slot 4 and 5 due to using Yanfly's Equip Core to allow for two accessory slots)

    Code:
    $gameParty.members()[2].equips()[4].id === 67 || $gameParty.members()[2].equips()[5].id === 67

    The thing is, this works perfectly in game. The only oddity is, if this check returns false, I get the following error in the console. (Also, just to note, even though EventCopier shows up in the error, disabling it gives the same error)

    View attachment 164900

    Could someone help me tweak my script to fix the errors showing up in the console?

    When an equip slot is empty and the conditional branch is checking for an equip id, it will return that error. Because it can't check the id of a non-existing equip.

    You have to include a check to see if an equip exists before checking it's id.
    Code:
    $gameParty.members()[2].equips()[4] && 
    $gameParty.members()[2].equips()[4].id === 67 || 
    $gameParty.members()[2].equips()[5] && 
    $gameParty.members()[2].equips()[5].id === 67

    It gets a bit messy. But that's the way to do it in this case.
  5. Lanzy said:
    When an equip slot is empty and the conditional branch is checking for an equip id, it will return that error. Because it can't check the id of a non-existing equip.

    Thank you for your help.

    Hmm... that seemed to fix one error, but now I'm getting a different error. Still works fine in game, but getting this error in the colsole, when using this script call.

    Code:
    $gameParty.members()[2].equips()[4] && $gameParty.members()[2].equips()[4].id === 67 || $gameParty.members()[2].equips()[5] && $gameParty.members()[2].equips()[5].id === 67

    Capture.PNG
  6. Vis_Mage said:
    Thank you for your help.

    Hmm... that seemed to fix one error, but now I'm getting a different error. Still works fine in game, but getting this error in the colsole, when using this script call.

    Code:
    $gameParty.members()[2].equips()[4] && $gameParty.members()[2].equips()[4].id === 67 || $gameParty.members()[2].equips()[5] && $gameParty.members()[2].equips()[5].id === 67

    View attachment 165070

    Yea, that means that the member of the party doesn't exist. So u wanna make another condition before checking equips, to check if party member exists.

    Note that members()[2] is actor no. 3 in the party list.
  7. Lanzy said:
    Yea, that means that the member of the party doesn't exist. So u wanna make another condition before checking equips, to check if party member exists.

    Note that members()[2] is actor no. 3 in the party list.
    Ah, that makes sense, thank you very much!

    In case anyone else is curious how to set it up, this is the script that I ended up using:

    Code:
    $gameParty.members().length >= 1 && $gameParty.members()[0].equips()[4] && $gameParty.members()[0].equips()[4].id === 67 || $gameParty.members().length >= 1 && $gameParty.members()[0].equips()[5] && $gameParty.members()[0].equips()[5].id === 67
  8. Hi, y'all. I was working on a skill that reduces the max HP of the target by 25% of the damage taken, and this is what I came up with:
    JavaScript:
    <Custom Deselect Effect>
    erosion = Math.round(value/4);
    target._paramPlus[0] -= erosion;
    target.removeState(59);
    </Custom Deselect Effect>
    This is in the note of a state that's applied in the damage formula.

    Unfortunately, it returns an error about not being able to draw the health bar because the value is non-finite, even though I'm making sure the erosion variable is rounded.
    Full error
    YEP_CoreEngine.js:1098 TypeError: Failed to execute 'createLinearGradient' on 'CanvasRenderingContext2D': The provided double value is non-finite.
    at Bitmap.gradientFillRect (rpg_core.js:1289)
    at Bitmap.gradientFillRect (YEP_CoreEngine.js:1014)
    at Window_VisualHPGauge.drawGauge (YEP_X_VisualHpGauge.js:717)
    at Window_VisualHPGauge.drawActorHp (WAY_X_VisualGaugesAddon.js:1146)
    at Window_VisualHPGauge.refresh (YEP_X_VisualHpGauge.js:641)
    at Window_VisualHPGauge.updateRefresh (YEP_X_VisualHpGauge.js:632)
    at Window_VisualHPGauge.updateWindowAspects (YEP_X_VisualHpGauge.js:544)
    at Window_VisualHPGauge.update (YEP_X_VisualHpGauge.js:536)
    at rpg_core.js:4068
    at Array.forEach (<anonymous>)
    If I replace -= erosion in the 3rd line by -= 100, it works perfectly. So the issue has to come from the erosion variable.
    So I have no idea what's causing the erosion value, a very much finite number because it gets rounded, to return this error.
    Can somebody tell me what's wrong, and how to fix it?
  9. I'm just gonna guess, 'cause it's rather late here.
    The issue might be the "value" variable.
    When the deselectStateEffect function calls the customEffectEval function, the "value" variable isn't provided, so it defaults to "undefined".
    Now you're trying to divide "undefined" by 4 what gets you NaN (Not a Number).
    You could try it with the <Custom Respond Effect> tag instead. The "value" variable there will have the damage value in it for that.
  10. kiriseo said:
    I'm just gonna guess, 'cause it's rather late here.
    The issue might be the "value" variable.
    When the deselectStateEffect function calls the customEffectEval function, the "value" variable isn't provided, so it defaults to "undefined".
    Now you're trying to divide "undefined" by 4 what gets you NaN (Not a Number).
    You could try it with the <Custom Respond Effect> tag instead. The "value" variable there will have the damage value in it for that.
    Well I didn't know I could both suck and be mildly proficient at JS. Thank you!
  11. Can anyone who knows javascript pick up mv and write plug ins for it or are there other things that person has to learn first? For example, if I tried to hire a JS programmer off another site, could they just jump right into MV? Or do they need to learn other things as well?
  12. Laya said:
    Can anyone who knows javascript pick up mv and write plug ins for it or are there other things that person has to learn first? For example, if I tried to hire a JS programmer off another site, could they just jump right into MV? Or do they need to learn other things as well?
    RPG has basic Plugins:
    Screenshot_3.png
    So if you hire someone who is used to JS, that person will still have to learn everything about what happens in those basic plugins.. and it would be better to know how the RPG systems works
    (I mean beein familiar with eventing and the engine itself in that case MV)
  13. I can concatenate a string and use $gameVariables.value(n)+" blind mice", I can force a line feed with "blind \n mice", but I don't know how to insert an icon in the js string to show in the message box. It just shows up as "3 \i[48] blind mice." Is it possible to do this?
  14. Lady_JJ said:
    I can concatenate a string and use $gameVariables.value(n)+" blind mice", I can force a line feed with "blind \n mice", but I don't know how to insert an icon in the js string to show in the message box. It just shows up as "3 \i[48] blind mice." Is it possible to do this?
    Im not sure if that solves your question but i found this topic.
    (RPG Maker MV Message Boxes: Special Characters)
    And this posting #4.. ( in the topic)
  15. Dopan said:
    Im not sure if that solves your question but i found this topic.
    (RPG Maker MV Message Boxes: Special Characters)
    And this posting #4.. ( in the topic)
    Thanks for helping me search, but this only relates to the special characters within the message box itself. What I really want to do is insert the icon into a javascript constructed string variable. I'm still searching, but it seems that because it's an image, it's not a simple thing.
  16. Lady_JJ said:
    Thanks for helping me search, but this only relates to the special characters within the message box itself. What I really want to do is insert the icon into a javascript constructed string variable. I'm still searching, but it seems that because it's an image, it's not a simple thing.

    The text in message boxes gets checked for special characters and then replaces them accordingly. You will need to run your string through the same interpreter. I'm too tired now to check, but if u give me time I'll check it out and let u know, since that would also be interesting for me to know.
  17. Thank you. I have decided to go a simpler route. I'm going to use multiple variables for the conventional text and just line them up accordingly. I had wanted to omit the icon if the quantity of that item were zero, but I'll just include the icon and note the quantity as zero. Still, if you decide to ever work this out, that would be amazing!
  18. I'm using Yanfly's Quest Journal System. Is there a function I can call that will return the title of a quest, with the quest ID being the argument to return the right one?

    I'm trying to automate creating Gab windows that indicate quest changes, using the Quest Journal's Lunatic Mode in the plugin settings. If I could just get a string that returns the title like I typed it in the plugin settings, I've got the rest covered.
  19. CHKNRAVE said:
    I'm using Yanfly's Quest Journal System. Is there a function I can call that will return the title of a quest, with the quest ID being the argument to return the right one?

    I'm trying to automate creating Gab windows that indicate quest changes, using the Quest Journal's Lunatic Mode in the plugin settings. If I could just get a string that returns the title like I typed it in the plugin settings, I've got the rest covered.

    Try using

    JavaScript:
    $dataQuests[questID];

    This might just return the entire quest, rather than the name.
    I don't know how it's structured. If you can use that code above in the console and post a screenshot, then I can give u more details.
  20. Lanzy said:
    Try using

    JavaScript:
    $dataQuests[questID];

    This might just return the entire quest, rather than the name.
    I don't know how it's structured. If you can use that code above in the console and post a screenshot, then I can give u more details.
    It was $dataQuests[questId].name. Thank you very much!

    In case anybody's having this issue in the future, here's what I'm putting in the Lunatic Mode code that's executed when a quest is added:
    JavaScript:
    var cmd = new Game_Interpreter();
    var line = 'New quest: ' + $dataQuests[questId].name;
    cmd.pluginCommand('GabText', [line]);
    cmd.pluginCommand('ShowGab');
    This will display the Gab window "New quest: " followed by the name of the quest (with its text codes) exactly like you entered it in the plugin settings of the Quest Journal plugin.