JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 140 of 171 View original ↗
  1. Jobhob said:
    "if both actor at 50% or more HP, state is removed AND if there is only 1 actor alive, if other actor has 50% or more HP, state is removed"
    The logic of what you wrote, and the logic you said you wanted it to follow are not the same. By your description, there are two sets of conditions where you want that state removed. How are they supposed to be separate if when you wrote it, theres only one line to remove the state? and in order to get to it, conditions for both have to be navigated through?

    if youre having trouble setting up logic, write down exactly what you want it to do statement by statement in plain english, and then start from there.
  2. Asking on behalf of another thread, is there an easy/efficient way to do this?

    loop through every event on the map to see if it had an <enemy> tag and ... check if the tile it's on has another event in it, then get that other event's id, then check if it has a <trap> tag. Then toggle the trap event's self switch (A)

    JavaScript:
    var enemyEvents = $gameMap.events().filter(function(event){return $dataMap.events[event._eventId].meta["enemy"] && !event._erased;});
    enemyEvents.forEach(function(enemy){
    //???
      }
    });
  3. AquaEcho said:
    loop through every event on the map to see if it had an <enemy> tag
    That'll be $gameMap.events() (because $dataMap will use where the events were placed in the editor, not necessarily where they are now).

    AquaEcho said:
    check if the tile it's on has another event in it
    That'll use eventsXy().

    The thing that's not clear without going to the other thread is what you want to do with those traps. What's the purpose of scanning every event on the map for this? It seems like you would only care when each individual event moves onto a tile that has a trap. Or something.

    But if you want an array of every trap event that has a monster event on it:
    Code:
    let triggered_traps = [];
    $gameMap.events().forEach(event => {if (event.meta.enemy) 
            $gameMap.eventsXy(event.x, event.y).forEach(shared => {if (shared.meta.trap) triggered_traps.push(shared);})});

    Edit: oops, fixed.
  4. ATT_Turan said:
    That'll be $gameMap.events() (because $dataMap will use where the events were placed in the editor, not necessarily where they are now).
    Thanks for pointing that out. I'm using that script in my game; I'll need to update it.
    you would only care when each individual event moves onto a tile that has a trap

    Yes, which would require aliasing Game_Event.prototype.moveStraight, which is why my first thought was to modify CT_Bolt's Event Trigger Event that already does that. This is the non-plugin Plan B.

    ATT_Turan said:
    But if you want an array of every trap event that has a monster event on it:
    Code:
    let triggered_traps = [];
    $gameMap.events().forEach(event => {if (event.meta.enemy)
            $gameMap.eventsXy(event.x, event.y).forEach(shared => {if (shared.meta.trap) triggered_traps.push(shared);})});

    Edit: oops, fixed.
    Ok, so to toggle the self switch A of every trap, something like this
    JavaScript:
    $gameMap.events().forEach(event => {if (event.meta.enemy)
            $gameMap.eventsXy(event.x, event.y).forEach(shared => {if (shared.meta.trap) $gameSelfSwitches.setValue([$gameMap._mapId, shared._eventId, 'A'],true);})});
  5. AquaEcho said:
    Yes, which would require aliasing Game_Event.prototype.moveStraight
    Or you just include it on the events themselves to check after they move whether they've landed on a trap.
  6. Robro33 said:
    The logic of what you wrote, and the logic you said you wanted it to follow are not the same. By your description, there are two sets of conditions where you want that state removed. How are they supposed to be separate if when you wrote it, theres only one line to remove the state? and in order to get to it, conditions for both have to be navigated through?

    if youre having trouble setting up logic, write down exactly what you want it to do statement by statement in plain english, and then start from there.
    Yeah, I guess that's was the problem. Basically it's like priorities, and it should behave like "Check if both actors are above 50% HP. If yes, remove the state", and "If one of actors is dead, check if other actor is above 50% HP. If yes, remove the state". Ig that requires two separate conditions.
  7. How can I get the specific notetag value of a skill? For example, I have a skill that has both <Cast Animation: 121><Cooldown: 10>, how will I get the value of cooldown?
  8. theres always the direct approach. look up the meta property for the skill's data entry and then look for the tag $dataSkills[x].meta.Cooldown
    That way always returns a string though, so youll have to keep that in mind.

    Depending on how the plugin is written though, it may also write a cooldown property into the skill as well. so if you take a look at the skill's data entry in the console, you might see something like a .cooldown property and can use that instead. chances are that it would already be a number
  9. What's the function that reduces HP when a character is poisoned?
  10. Fionn23 said:
    What's the function that reduces HP when a character is poisoned?
    Without any context, I'm not sure what you're going for. Do you want the higher or lower level part of it?

    Ultimately, all reduction of HP in the engine goes through gainHp(). If you're looking for the specific track of regeneration effects, that comes from Game_Battler.endTurn(), and you can follow the function calls from there.
  11. I just saw this thread and in it @ATT_Turan posts the solution:

    ATT_Turan said:
    Code:
    $gameParty.members().some(actor => actor.addedSkillTypes().includes(X))

    where X is the number of the type you're looking for.

    I still don't understand how it is that with someArray.some(a => a.someOtherArray().includes(X)) javascript knows which object you're talking about... like... how does it know?
  12. werzaque said:
    I just saw this thread and in it @ATT_Turan posts the solution:



    I still don't understand how it is that with someArray.some(a => a.someOtherArray().includes(X)) javascript knows which object you're talking about... like... how does it know?
    Because you told it?
  13. I guess so but how? I've never told "it" that actor = $gameParty.members()[n]...
  14. werzaque said:
    I guess so but how? I've never told him that actor = $gameParty.members()[n]...
    You told it the array $gameParty.members()

    "actor" is just an index in the array
  15. Thanks... it still doesn't dawn on me but I'll try some exercises outside of rpg maker to see how it works...

    Confused because something like this works:
    JavaScript:
    const GameParty = [
        {name: 'Jan', nationality: 'German'},{name: 'Pieter', nationality: 'Dutch'},{name: 'William', nationality: 'British'}
        ];
    alert(GameParty.some(a => a.nationality == 'Dutch'));

    But if I try the same without the arrow it doesn't...
    JavaScript:
    const GameParty = [
        {name: 'Jan', nationality: 'German'},{name: 'Pieter', nationality: 'Dutch'},{name:'William',nationality:'British'}
        ];
    function SomeFunc(a){
         return GameParty[a].nationality == 'Dutch';
    }
    alert(GameParty.some(SomeFunc(a)));
  16. werzaque said:
    Thanks... it still doesn't dawn on me but I'll try some exercises outside of rpg maker to see how it works...

    Confused because something like this works:
    JavaScript:
    const GameParty = [
        {name: 'Jan', nationality: 'German'},{name: 'Pieter', nationality: 'Dutch'},{name: 'William', nationality: 'British'}
        ];
    alert(GameParty.some(a => a.nationality == 'Dutch'));

    But if I try the same without the arrow it doesn't...
    JavaScript:
    const GameParty = [
        {name: 'Jan', nationality: 'German'},{name: 'Pieter', nationality: 'Dutch'},{name:'William',nationality:'British'}
        ];
    function SomeFunc(a){
         return GameParty[a].nationality == 'Dutch';
    }
    alert(GameParty.some(SomeFunc(a)));
    some is a function that expects another function as an argument. SomeFunc(a) returns a boolean, not a function. You'd need to either do a => SomeFunc(a) or just SomeFunc (without invoking it - this passes the function itself, not its result).
  17. Thank you so much! I failed to realize that a => a.nationality == 'Dutch' by itself is not returning anything (yet). No, not the correct wording but I think I understand. Phew!

    JavaScript:
    const GameParty = [
        {name: 'Jan', nationality: 'German'},{name: 'Pieter', nationality: 'Dutch'},{name:'William',nationality:'British'}
        ];
    function SomeFunc(a){
         return a.nationality == 'Dutch';
    }
    alert(GameParty.some(SomeFunc));
  18. werzaque said:
    Thanks... it still doesn't dawn on me but I'll try some exercises outside of rpg maker to see how it works...
    Have you simply looked up the documentation/tutorials on arrow functions?

    JavaScript Arrow Function
    werzaque said:
    I guess so but how? I've never told "it" that actor = $gameParty.members()[n]...
    Again, I think looking it up is your friend.

    W3Schools.com
    That's what the some() method means - "do this on each element of the array, and I'm going to call the current element 'actor' "
  19. ATT_Turan said:
    That's what the some() method means - "do this on each element of the array, and I'm going to call the current element 'actor' "
    Thanks. Yeah, I get that now (or more precisely I decided that it's what it is...), but it really wasn't obvious to me that it assumes "a" or "actor" or whatever you decide to call it as a return value. That part still feels like magic to me.
  20. It's not magic: some simply calls the function with the relevant values for each element. This is mentioned on the page Turan linked.

    Functions in JS can always accept any number of inputs. The names those inputs may be given are relevant only within the function itself.