JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 98 of 171 View original ↗
  1. ATT_Turan said:
    I'm confused by your wording as to whether you want to add the value of 873 to each of those other variables IFF they are greater than 0; or if you want to get one number that is the sum of all of those?

    Either way, you'd just access the variables array directly: $gameVariables._data[index]

    So you can make a loop that goes through that and does whatever you intended to say, or use the JavaScript inherent array functions, whatever.
    The first one is what I was hoping to do, add the value of 873 to each variable from within the range that had a value greater than 0. Although, both would honestly be really helpful to know.
  2. Vis_Mage said:
    The first one is what I was hoping to do, add the value of 873 to each variable from within the range that had a value greater than 0. Although, both would honestly be really helpful to know.
    I'd suggest you do some JavaScript tutorials (I like w3schools, but there are a bunch of sites). There's nothing wrong with asking questions, but you've been asking a bunch and most of them (like this) are pretty basic - so at some point it takes less time to just learn than to ask the question :stickytongue:

    So you just do a basic loop.
    Code:
    for (var i=800; i<873; i++)
    {
        if ($gameVariables._data[i]>0)
            $gameVariables._data[i]+=$gameVariables._data[873];
    }

    As far as adding them all up, that's even more basic...
    Code:
    var sum=0;
    for (var i=800; i<=873; i++)
        sum+=$gameVariables._data[i];
  3. Hey :) So I know I can use (this._eventId) to get the id of the current running event, but is there something similar to get the ids of all events in the current map so that I could affect them all at once to display an effect for example?
  4. raffle said:
    Hey :) So I know I can use (this._eventId) to get the id of the current running event
    Note that this is a JavaScript reserved word, so that only works when you're writing code executed by an event.
    raffle said:
    is there something similar to get the ids of all events in the current map
    The events for the current map are an array returned by $gameMap.events()

    You can do anything to that that you can do to an array. If that's not helpful enough for your skill level, you should start a new thread describing exactly what you're trying to accomplish and we'll see what we can do.
  5. Is there anyway to set a % on 'add state x' action on YEPs action sequences?
  6. Create a thread for that, unless you ask a JS syntax, it goes here.
  7. Quest question, I'm currently using those script call to force use an item on a actor who's ID is determined by a variable. (Code originally found here: https://forums.rpgmakerweb.com/inde...e-item-effect-use-on-map-in-main-menu.118167/)

    Would someone be able to help me adjust it, to make it target all party members instead?

    Code:
    var itemId = $gameVariables.value(21), actorId = $gameVariables.value(22);
    (function(v,i,t,a,c,u) {
    if (i = $dataItems[+v || 0]) {
    u = $gameParty.members()[$gameActors.actor(actorId).index()];
    a = new Game_Action(u); a.setItemObject(i);
    t = i.scope === 7 ? [u] : a.makeTargets();
    for (n in t) c = c || a.testApply(t[n]);
    if (u.canUse(i) && (i.scope === 0 || c)) { u.useItem(i);
      $gamePlayer.requestAnimation(i.animationId);
      a.apply(t[n]); a.applyGlobal();
    }}})(itemId);
  8. thats probably a stupid question, but what does " !! " mean?

    i know that a single "!" means "not"

    but i was reading in a plugin code where " !! " was used
    (screenshot)
    Screenshot_3.png
    .. and i am not sure if thats an typo mistake and does the same as "!" or if it means something else..
  9. Apparently, it is to convert any variable to a boolean value (true or false).
  10. Vis_Mage said:
    Would someone be able to help me adjust it, to make it target all party members instead?
    Does it not do it automatically if you set the scope of the item to All Allies?

    While you've brought it up, what the heck is this saying?
    Code:
    if (i = $dataItems[+v || 0])
  11. Running the above code using an item that is set to target all allies still only seems to affect the actor that the code uses the item on.

    As for that bit of code, I'm not actually quite sure. Besides modifying it so the item and actor ID's are determined by the value of a variable, I got this bit of code from the linked post.
  12. This is probably really obvious but

    Any given actor in a game I'm working on will wind up having eight skills total, and I'm looking for a way to make a variable for each of those skills to use in dialogue, choices, text, etc.

    Specifically for the currently known skills.
    Example, Character A knows skills 1, 2, 3, 4, 5, 6
    var 1 should be 1
    var 2 should be 2, etc
    But if Character A instead knows skills 3, 4, 5, 6
    var 1 should be 3
    var 2 should be 4, etc

    So how exactly would I got about getting, for example, the first known skill that actor 1 has.
    I believe I have to do something with $gameActors.actor(1).skills()) but I'm not quite sure how to do it.

    Thanks.
  13. Flame_Effigy said:
    Any given actor in a game I'm working on will wind up having eight skills total, and I'm looking for a way to make a variable for each of those skills to use in dialogue, choices, text, etc.
    How you do this depends a lot on how your skills work. Are you just using the default "class X gets skill Y at level Z" system, or something else?

    Are the actors the same class throughout the game, or can they change? If yes, does that affect their skills?

    What do you consider to be "the first known skill?" Is it the default skill system and it's the earliest-level skill they learned? Is it the one with the lowest skill ID? Do you have some kind of skill equip system and it's whatever is in skill slot 1?
  14. ATT_Turan said:
    How you do this depends a lot on how your skills work. Are you just using the default "class X gets skill Y at level Z" system, or something else?

    Are the actors the same class throughout the game, or can they change? If yes, does that affect their skills?

    What do you consider to be "the first known skill?" Is it the default skill system and it's the earliest-level skill they learned? Is it the one with the lowest skill ID? Do you have some kind of skill equip system and it's whatever is in skill slot 1?
    Class gets Y skill at Z level.
    No skills changed by class.
    Earliest skill they learned I suppose. Lowest skill ID would be fine too.
    If I did have a skill equip system I would want equipped skills excluded. Would it be possible to only check for a specific type of skill in that instance?

    The reason I'm trying to do it this way is actors will lose skills of their choice through dialogue choices so setting up the variables to be dependent on the actors' currently known skills seemed like the right way to go.
  15. Flame_Effigy said:
    Class gets Y skill at Z level.
    Earliest skill they learned I suppose.
    The easiest way to do that would be to iterate through $dataClass[the actor's class].learnings[] but this won't work well for you since you'll be having them forget skills later
    Flame_Effigy said:
    If I did have a skill equip system I would want equipped skills excluded. Would it be possible to only check for a specific type of skill in that instance?
    Look up JavaScript's array.filter()
    Flame_Effigy said:
    The reason I'm trying to do it this way is actors will lose skills of their choice through dialogue choices so setting up the variables to be dependent on the actors' currently known skills seemed like the right way to go.
    This sounds less like a specific, minor JavaScript question, and more like a new thread you should start to figure out how to set up this system.

    Before doing so, you need to determine exactly how you want your entire skill system to work, because you have a number of places where you seem uncertain or undecided, so no one can help you do a specific thing until you've decided upon it.

    I would suggest looking at calling common events when leveling up to add any new skills to your variables, and then whatever event you use to discard a skill for a new one should be able to modify the appropriate variable then.
  16. ATT_Turan said:
    The easiest way to do that would be to iterate through $dataClass[the actor's class].learnings[] but this won't work well for you since you'll be having them forget skills later
    Okay so just for my sake. The real meat of my original question is that I'm looking to turn a character's currently known skills into variables in a standard level up system. The rest of it is unimportant at the moment.

    The best way to go about this would be to set up a common event on level up and alter the variables there?
    I was under the impression that $gameActors.actor(1).skills()) returned all the currently known skills of actor 1 as an array but when I try to reference them I just get object Obejct in the message boxes
  17. Flame_Effigy said:
    I was under the impression that $gameActors.actor(1).skills()) returned all the currently known skills of actor 1 as an array but when I try to reference them I just get object Obejct in the message boxes
    Yes, it does. I don't know how you're referencing them as you don't provide an example of your code, but for example: $gameActors.actor(1).skills()[0] will return the first skill actor ID 1 learned (before any messing with forgetting and learning more stuff).

    Note that just looking at a skill is going to give you exactly what you saw, as a skill is an entire data type. You would want to look at its id or its name via the appropriate member variable (e.g. $gameActors.actor(1).skills()[0].name ).

    You may find this reference useful in your endeavors:

    Flame_Effigy said:
    The best way to go about this would be to set up a common event on level up and alter the variables there?
    The reason I say that is so that you can just have a list of variables for each character with the name of the skill stored, which lets you use regular text escape codes to refer to them. Otherwise, every time you want to reference that list you'll have to be using script calls like the above instead of just, say, \v[0]
  18. ATT_Turan said:
    Yes, it does. I don't know how you're referencing them as you don't provide an example of your code, but for example: $gameActors.actor(1).skills()[0] will return the first skill actor ID 1 learned (before any messing with forgetting and learning more stuff).

    Note that just looking at a skill is going to give you exactly what you saw, as a skill is an entire data type. You would want to look at its id or its name via the appropriate member variable (e.g. $gameActors.actor(1).skills()[0].name ).

    You may find this reference useful in your endeavors:
    Thank you very much that is what I needed to know.
  19. If I am understanding it correctly, if I have multiple instances of "<variable> *=", then as long as each instance of <variable> is a number, it will result with a multiplicative product of those numbers?
    (e.g. three instances of <variable> has 0.9, so <variable> = 0.9 * 0.9 * 0.9 = 0.729)?
  20. You can quickly try in the browser by pressing F12 and writing in the console
    JavaScript:
    var a = 0.9
    a *= 0.9
    a *= 0.9
    to find out.