JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 160 of 171 View original ↗
  1. ATT_Turan said:
    Can you explain more what the point of this is? Part of loading the game in RPG Maker is loading the map and location where the player was, but you say you don't want that - so what's the point? What do you need some other data for?
    I'm making a point-and-click game instead of an exploration one that is rather short--it's an educational game meant for kids with 5 levels. Each level has a puzzle and every time the level is completed, it will unlock another level.

    The player can return to the completed level anytime they want, so I'm saving their progress data every time they finished a level. There's a score data too, which will be needed to unlock badges and stuff.

    I'm doing a single-file save that will autosave every time the player completed the level, and since it will mostly be played in smartphones, I'm just trying to imitate mobile games that saves your progress after completing a level (similar to mobile games like Farm Heroes Saga or Candy Crush Saga where they show the title and automatically load the player's progress and send them to the level selection menu instead of where they left off)
  2. @gtoff Okay - my advice above stands :smile:
  3. ATT_Turan said:
    @gtoff Okay - my advice above stands :smile:
    Alright, I'll check them out; thank you for the advice!
  4. I feel bad, it feels everytime I comeback to this forum I have a weird problem, well its what happens when my brain refuses to lear how "code" actually works XD.

    So I'm trying to do this. so I'm using Yanfly - Toxic (MV Plugin Tips & Tricks) and I managed to create the HP-reducing effect with no problem, now I tought, how about I also make also an MP drain one, when I went ahead and test it however I got this error.

    1733503212514.png

    I said, huh, maybe the ST0RM plug-in is causing issues... so I turn it off saved and test again.

    1733503372110.png

    So the error is still there, I tried testing the HP one again, and that one works fine. So this is the original Toxic code

    JavaScript:
    <Custom Regenerate Effect>
    var n = this._toxicCounter / 8;
    var value = Math.floor(n * user.mhp * -1);
    user.gainHp(value);
    this._toxicCounter += 1;
    </Custom Regenerate Effect>

    And this is what I was using to just test the MP reduction

    JavaScript:
    <Custom Regenerate Effect>
    var n = this._toxicCounter / 8;
    var value = Math.floor(n * user.mmp * -1);
    user.gainMp(value);
    this._toxicCounter += 1;
    </Custom Regenerate Effect>

    So... any idea what's going on?

    And thanks in advance to anyone willing to help, or bounce ideas.

    Edit: BTW normal MP negative regeneration works fine, I can set it up to -10% and that works.
    Edit: Solved due to me not being careful enough to check if I was actually applying the counter, @Robro33 is correct, it was trying to divide by 0 due to not applying the toxic counter on the same state.
  5. it would help to show the entirety of the state's notebox.

    my guess is that you dont have something prior setting the _toxicCounter, so the gainMp crashes the game when it causes the hp to become NaN
  6. Now I feel stupid... again, yes your are right I just notice I'm not applying the counter at all...:kaoeh:
  7. Is there a way to get the current duration of a state? I'm trying to make a state that damages HP every turn equal to the state's current duration in turns.

    Edit: My bad, there was a script call for it. Sorry. :kaocry:
  8. DecastarDaDumy said:
    Is there a way to get the current duration of a state? I'm trying to make a state that damages HP every turn equal to the state's current duration in turns.
    if you have the actor reference, its
    Code:
    actor._stateTurns[stateId]
    if you use yanfly's buffs and states plugin it also adds a function for it
    Code:
    actor.stateTurns(stateId)
  9. Robro33 said:
    if you have the actor reference, its
    Code:
    actor._stateTurns[stateId]
    if you use yanfly's buffs and states plugin it also adds a function for it
    Code:
    actor.stateTurns(stateId)
    I just wanna ask how to get that actor ref? Been trying to fiddle with it for a bit and it doesn't seem to work:
    Code:
    <Reapply Add Turns>
    <Custom Regenerate Effect>
    target.gainHp(-Math.round(actor.stateTurns(9)));
    </Custom Regenerate Effect>
  10. DecastarDaDumy said:
    I just wanna ask how to get that actor ref? Been trying to fiddle with it for a bit and it doesn't seem to work:
    in that case, the reference is target
  11. Hi,

    I'm trying to use Yanfly's Buff and States Core for MV to try to create a state wherein anyone who has it will take damage anytime they're debuffed.

    <Custom Respond Effect>
    if (target.result().addedDebuffs.length>0)
    {
    target.gainHp(-200);
    }
    </Custom Respond Effect>

    That's what I have so far, not sure what I'm doing wrong exactly.

    Thanks!
  12. @staticispunk When you call the Respond Effect, debuffs and other effects attached to the skill haven't been executed yet.

    Respond happens immediately after damage is executed (Game_Action.executeDamage()), and effects aren't added until the line after that in Game_Action.apply().

    You would have to use a Deselect effect.
  13. Back with another one! Thanks for your help previously. This should be a state which causes the affected actor to be healed whenever they remove a state from someone else.

    <Custom Deselect Effect>
    if (target.result().removedStates.length > 0)
    {
    user.gainHp(user.mhp/10);
    user.startDamagePopup();
    }
    </Custom Deselect Effect>

    Thanks!!
  14. staticispunk said:
    Custom Deselect Effect
    if the state has to do something as a result of the affected battler doing something, you want the tags labeled with "attacker", not "defender"
  15. Three quick questions.

    For context, this is the thread that prompted these questions. It was one of my very old threads and I didn't really understand the answer back then. I am trying to understand it better now.

    Easier way to do Common Event random non-repeating results?
    #1 Here is a suggested way of making an array of sequential numbers from 0 to whatever number you want. In the example below, it is 0-3.

    [...Array(4).keys()]

    I have read the few things about it that I could find and I read about the parts (... and .key()) and there was mention in a Reddit thread that maybe this isn't the best thing to do with JavaScript.

    If there could be problems with using this in RPG Maker, could someone clarify what those problems might be and if there is a better way to do something like this.

    #2 If this is actually a viable way of making a large array of sequential numbers, without potential problems, is there a simple way to modify it so it doesn't start at 0? I think the answer is no based on what I have read about what this is doing, but I thought I would ask, just in case.

    So you could have 1-100 instead of 0-99?

    #3 Finally, I am using this recommended script to shuffle the array.

    for (let i = options.length - 1; i > 0; i--) {
    const index = Math.randomInt(i + 1);

    const tmp = options;
    options = options[index];
    options[index] = tmp;
    }

    I have tested this and it works fine. I was just wondering if there was an even simpler way to do it.

    Thanks for any clarification you can provide!
  16. Quickest way without changing too much of what you already have is:

    JavaScript:
    [...Array(4).keys()].map(x=>++x);

    Which creates an array 0-3 and then maps the value of each to increase its value by 1.

    You can always create the arrays and then just do .shift() to remove the first array (value 0).

    The shuffling method you wrote is unbiased (Dursetenfeld shuffle I think - or Fisher-Yates) so it works well.
  17. ZombieKidzRule said:
    Three quick questions.
    1)
    i dont know why you wouldnt want to use your listed method, but you could write a little loop that starts and ends where you want and pushes the values into the array too if that works for you
    Code:
    var result = [];
    for (var i = x; i <= y; ++i) result.push(i);
    where x is where you start and y is where you end

    2 )
    also with your previous method, if you wanted to remove the 0, but it always starts with 0, you could splice out the first element before use every time

    3)
    you could try using sort() for that.
    options.sort(() => Math.random() - 0.5);
  18. @bass2yang Thanks! Very cool!

    I actually saw that .map(x=>++x) on one of the JS course pages, but I wasn't sure it would be relevant here or how to combine them.

    I just tested this and it works perfectly fine.

    @Robro33 Thanks! I will also try the options that you have suggested so I have options. I like learning different options and it is slowly getting easier to understand what is going on.

    EDIT: This also works great!

    for (var i = 1; i <= 10; ++i) $gameVariables.value(861).push(i);

    EDIT EDIT: And this works great also!

    $gameVariables.value(861).sort(() => Math.random() - 0.5);
  19. ZombieKidzRule said:
    $gameVariables.value(861).sort(() => Math.random() - 0.5);
    I believe this will produce bias? Like @bass2yang pointed out, use the Fisher-Yates algorithm (given to you by Nolonar in that thread) for an unbiased shuffle.
  20. @caethyril Thanks for that!

    I wasn't 100% sure what bias and unbiased meant in this context, but The Google just helped me understand. I can see how in some circumstances, like you are only doing this once per game experience, it probably wouldn't matter. But if you are doing this repeatedly, like for a card game or something, then I would definitely want the unbiased approach.

    Thank you so much for clarifying and I will add this to my notes regarding the two methods!

    I wanted to reach out and thank Nolonar again for their very detailed response in that thread, but I don't think they have been around the forums for quite some time.