JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 132 of 171 View original ↗
  1. Hullo, today's questions have to do with arrays! As always, if it's too complicated for here, let me know and I'll make it into its own thread.

    1. Do you guys know of any hard limits for arrays in RMMV? Like, I am planning an array with 500 indexes, will the game be able to handle this or should I keep the indexes to a lower limit? I don't want to go through coding the whole thing only to find out it's a bad idea later...!

    2. Is it possible to save which index you are looking at at the moment, and then proceed from there further on in the event? For example, I have an array with 10 indexes. At the moment, I am manually checking all then of them with 10 individual conditional events, and if they are !=0, proceed. However, it would be great if I could write it so it finds the next one that is not a Zero, does XYZ, and then finds the next one after this one that is not a Zero.

    What I'm doing now:

    Array [0,2,3,0,5]
    Check index [0] - it's zero so it's skipped.
    Check index [1] - it's 2 so the conditional branch runs.
    And so on.

    I know you can find the next index that is a certain value n by using $gameVariables.value(788).indexOf(n) which is great but not helpful here, because if I check for only those that aren't 0 it will stop as soon as it reaches index [1] in the example, right?

    What I ideally want it to do is run the command - it automatically skips index [0] cause that's zero, runs the conditional branches for indexes [1] and [2], automatically skips index [3], and executes index [4].

    Is this possible?
    Thank you!
  2. stopbeingbored said:
    Like, I am planning an array with 500 indexes, will the game be able to handle this or should I keep the indexes to a lower limit? I
    That in itself is not a problem at all - at millions of entries you'll start running into serious RAM usage problems, but just 500 numbers shouldn't noticeably impact your RAM usage / savefile size. What you do with that array is another question - if you'll be doing something for every element of it, and that thing is rather slow, that could be a problem. But the very existence of a long array won't be.

    stopbeingbored said:
    2. Is it possible to save which index you are looking at at the moment, and then proceed from there further on in the event? For example, I have an array with 10 indexes. At the moment, I am manually checking all then of them with 10 individual conditional events, and if they are !=0, proceed. However, it would be great if I could write it so it finds the next one that is not a Zero, does XYZ, and then finds the next one after this one that is not a Zero.
    Ideally you'd use a for loop - it's a very versatile tool for doing things on arrays, though using it will require learning some more JavaScript. If you just want all non-zero values, you can get them with $gameVariables.value(788).filter(x => x!==0) - this will create another array with all 0-values removed.
  3. Mac15001900 said:
    Ideally you'd use a for loop - it's a very versatile tool for doing things on arrays, though using it will require learning some more JavaScript.
    Thank you very much. I've been reading a bunch of for loop tutorials and they are starting to make more sense to me, so I will try experimenting with these (and no doubt ask you all for help a billion times along the way). I'll also have a look through the loops other users kindly suggested to me in other threads to see if I can follow the logic now.

    Mac15001900 said:
    If you just want all non-zero values, you can get them with $gameVariables.value(788).filter(x => x!==0) - this will create another array with all 0-values removed.

    Possibly a silly question, but with this code, where does the new array get saved? I assume it takes all non-zero numbers from array var 788 in this example, but does the new array overwrite the old one? I would like to avoid that if possible.

    Or is it a matter of setting Variable 789 == the above code, for example?

    Thanks again!

    EDIT:
    Would it be something like this? I assume I then have to script the whole rest of what I want to do in JavaScript as well instead of using the MV commands, correct?

    for (i = 0; i < $gameVariables.value(1).length; i++) { if ($gameVariables.value(1)[i] !=0){ $gameVariables.value(1)[i] = $gameVariables.value(2); //execute the rest of the stuff here using what is stored in game variable 2 as a base } }
  4. stopbeingbored said:
    Or is it a matter of setting Variable 789 == the above code, for example?
    That is correct, filter only returns the new array, without modifying the existing one. It's not a particularly silly question either, given that some other functions (e.g. sort()) do modify the existing array.

    stopbeingbored said:
    Would it be something like this? I assume I then have to script the whole rest of what I want to do in JavaScript as well instead of using the MV commands, correct?
    Indeed. Theoretically you could call a common event with JavaScript, though that probably won't be very efficient - I'm not sure what the engine will think about 500 events being called nearly simultaneously xD

    Alternatively you could do the same thing with an event - create an index variable, a loop, increment the variable at the end of the loop, and exit if it hits the length of the array. Mostly depends on how difficult it will be for you to write JavaScript for what you want to do.

    If you go with option 1, here's a helpful reference on how to do everything events can do with JavaScript.

    stopbeingbored said:
    $gameVariables.value(1)[i] = $gameVariables.value(2);
    Is that not the other way round? I'm guessing you wanted to set variable 2 to the value from the array, but if so you've done the opposite.
  5. @Mac15001900 Thank you again, super helpful. At this point, with everyone's combined advice, 90% of what I want to do is in script calls already anyway so hopefully it won't be too much of a chore at this stage. And thanks for catching my error at the end there :biggrin:
  6. I need.... A pretty decent amount of help getting my SV Battler system setup. I've got some compatibility issues with Jeneeus Guruman's Graphics auto changer, and Yanfly's Party System. I also am using YED_Sideview Battlers to give my battlers more customizable frames.

    But it seems like those 3 plugins are not going to play well together.
    Would this be an appropriate place to ask about advice/help with figuring this out, or should I start a new thread?
    If so, what would be the most appropriate place to post said thread?

    My project is pretty much at a total stand still at the moment until I can get this figured out.
    I'm using RPG Maker MV btw.
  7. mr_ringtales_workshop said:
    But it seems like those 3 plugins are not going to play well together.
    Not sure if it will help you since it involves changing plugins as well as your spritesheets, but Lib's battle motion is compatible with Yanfly Battle Engine Core if I understood correctly.
  8. werzaque said:
    Not sure if it will help you since it involves changing plugins as well as your spritesheets, but Lib's battle motion is compatible with Yanfly Battle Engine Core if I understood correctly.
    Ooooo thank you! I'll check it out. I've been wracking my brain all night trying to find a solutionXD
  9. mr_ringtales_workshop said:
    Would this be an appropriate place to ask about advice/help with figuring this out
    As you're not asking anything about JavaScript in the thread titled JavaScript questions...I'm gonna venture no :p

    mr_ringtales_workshop said:
    If so, what would be the most appropriate place to post said thread?
    There's a whole forum titled Plugin Requests.

    When you post there, please provide links to the plugins you're asking about. Not everyone has used every plugin (I've never even heard of a few you're talking about).
  10. ATT_Turan said:
    As you're not asking anything about JavaScript in the thread titled JavaScript questions...I'm gonna venture no :p


    There's a whole forum titled Plugin Requests.

    When you post there, please provide links to the plugins you're asking about. Not everyone has used every plugin (I've never even heard of a few you're talking about).
    LOL SORRY, it says javascript/plugin support, so that's why I asked, I pretty rarely get on the forums and often feel kinda lost XD I wasn't sure if this thread was a catch-all for this sub section (javascript/plugin support) or if this was specific to just javascript, definitely my bad lol!


    And yes definitely, I didn't want to bog this post down with all the links and stuff if this was in fact not the right place. I always get a bit nervous posting on the forums in general because of that sweet sweet social anxiety + general lack of experience with online forums in general XD

    Thank you for pointing me in the right direction!
  11. Hello all
    I want to make a farm sim and I am using Yanfly
    self Switch & Variable link here
    Event Copier link here
    Event Morpher link here.
    My crop system works as follows:

    Page 1
    1.PNG
    When the seed has been planted the tile turns into this event and does two things on Autorun
    1.Sets variable 21 Self Var Alpha to 1 (this is for testing purposes)
    2.Turns self swith A On.

    Page 2
    2.PNG
    After Page 1 is done doing its job we move to page 2 and wait for player to press the tile
    the check is done in the following way:
    1.Check if switch Equipped_WateringCan is ON ( this is a switch that is turned on and off by another common event)
    If No: nothing happens​
    If Yes: Check if the player has "water" inside the can (Variable Uses Watering Can)​
    If No: play Show Balloon Icon ( a self made icon showing no water in watering can)​
    If Yes:​
    1.Both Variable 21 Self Var Alpha (from page 1) and Variable 11 Uses Watering Can are decreased by 1​
    2.A common event that checks if the watering can still has water is run (Not important)​
    3.A check to see if Variable 21 is equal to 0 in order to see if the tile can advance to the next crop level​
    If Yes:​
    1.(using another yanfly plugin) the event is morphed into the next stage​
    2.using the Exit Event Processing in order to stop the Self Switch B from turning ON​
    4.If the code does not enter into the IF in point number 3 then Self Switch B is turned ON​
    and we move to Page 3 where all that changes is just the Image showing a wet tile.​
    Ive made a common event to take care of the part that when it rains variable 21 Self Var Alpha will be decreased by 1 and also the Self Switch B will be turned ON
    3.PNG
    Plugin Command : SelfVariable Map 1, Event 13, Variable 21 to value - 1
    If you'd look at the first two pictures you will see the event ID is 4 while in the command it says 13
    this is because of the Event Copier from Yanfly

    Script : $gameSelfSwitches.setValue([ 1, 13, "B"], true)
    Same as the plugin command but this time its a script and its for the SelfSwitch

    and now for my problem and question ( finally)
    I want this Common Event to also check if Variable 21 inside Event 13 on Map 1 is equal to 0
    and if Yes run the following script:
    Yanfly.MorphEvent(this.eventId(), 4, 5, true)

    I don't have knowledge on how to structure the code so id be grateful if someone could write it for me

    thank you all for taking the time reading this.
  12. @Zuque I don't have my laptop at the moment but I am using some of the same plugins for the same purpose as you.

    If you check the Yanfly Self Var/Self Sw plugin, there's script calls listed that give you the value of an event's self switch. The script call is something like this.getSelfVariableValue(MapID, EventID, VariableID) or something like that.

    If you don't want to do any scripting, you can set a variable in your common event to this script call (the Variable options include an option for a script call at the bottom) and for example set Variable 1 = your event's self variable 21...

    Alternatively, if nobody else helps out with the exact script command by Tuesday I can help with this once my laptop is back from repair. But it should be something along the lines of:

    $gameVariable.setValue(1, this.getSelfVariableValue(1,13,21))

    Once this is done, you just run a conditional branch checking if Variable 1 (or whichever one you used) = 0.

    /EDIT to add: Alternative alternative, just do a conditional branch with a script command that is something like

    this.getSelfVariableValue(1,13,21) == 0

    That should work too I think
  13. Sorry everyone, no idea why that double posted instead of editing the OG post!
  14. stopbeingbored said:
    @Zuque I don't have my laptop at the moment but I am using some of the same plugins for the same purpose as you.

    If you check the Yanfly Self Var/Self Sw plugin, there's script calls listed that give you the value of an event's self switch. The script call is something like this.getSelfVariableValue(MapID, EventID, VariableID) or something like that.

    If you don't want to do any scripting, you can set a variable in your common event to this script call (the Variable options include an option for a script call at the bottom) and for example set Variable 1 = your event's self variable 21...

    Alternatively, if nobody else helps out with the exact script command by Tuesday I can help with this once my laptop is back from repair. But it should be something along the lines of:

    $gameVariable.setValue(1, this.getSelfVariableValue(1,13,21))

    Once this is done, you just run a conditional branch checking if Variable 1 (or whichever one you used) = 0.

    /EDIT to add: Alternative alternative, just do a conditional branch with a script command that is something like

    this.getSelfVariableValue(1,13,21) == 0

    That should work too I think
    First of all thank you for the reply
    to add a non self variable isn't going to work for me
    as i am trying to use as less variable as I can and designating variable 1 just for the use of event 13 will defeat this purpose as i am planning on having about a 100 crop tiles .

    but your comment on the javascript part of the selfvar got my gears turning and i came up with this
    of course it currently has problems too but as i see it they are smaller , its just my lack of javascript knowledge that's in the way
    4.PNG
    my current problem is that line 3 in the script part
    I am setting Self Var Alpha (variable 21) to 10 inside the event
    and by checking the F8 > Console I can see that according to the first line it is indeed 10
    but after it goes thru line 3 it somehow ends as -2
    so i don't know how to correctly do the calculation inside that function
  15. @Zuque From the first post in this thread:
    Shaz said:
    If you need help getting a plugin working, please start a NEW thread

    JavaScript that is specific to a plugin should have its own thread.

    However, to quickly answer you, your problems are because for some reason you're splitting your code up into multiple Script commands. Every Script command is its own eval, which means when you use one command to create var value then you use another Script command, that's gone out of scope and referencing value is undefined.

    You should have everything in one Script box.
  16. ATT_Turan said:
    @Zuque From the first post in this thread:


    JavaScript that is specific to a plugin should have its own thread.

    However, to quickly answer you, your problems are because for some reason you're splitting your code up into multiple Script commands. Every Script command is its own eval, which means when you use one command to create var value then you use another Script command, that's gone out of scope and referencing value is undefined.

    You should have everything in one Script box.
    Hot digidy da!

    thank you soo much!
    it worked.
  17. Hi, everyone! I just found this little JS snippet to show an animation on a follower? But it's for MV; I wondered if anyone would know how to replicate this effect in MZ?

    JavaScript:
    $gamePlayer.followers().follower(0).requestAnimation(1);
  18. @Allusion See the pinned MZ Script Call List:
    RPG Maker MV / MZ Script Call List
    Code:
    $gameTemp.requestAnimation([character], animationId, mirror);

    The follower bit would be what you put as character.
  19. I'm sorry if I don't phrase this right. But I think I might have asked this in Ruby thread but forgive me if this is a re-ask here. I just need a bit of a refresher, and I haven't been able to get a good search result answer. But I've been using "const" to add code into an already existing function like this:
    Spoiler
    Code:
    const Game_Actor_Refresh_Auto_States = Game_Actor.prototype.refresh;
    
    Game_Actor.prototype.refresh = function() {
        Game_Actor_Refresh_Auto_States.call(this);
        this.addAutoStates();
       //Other coding stuff
    };

    And I'm wondering if this is the most efficient way to go about things or if there's a way to slim down the code. Its more of a pet peeve but seeing all these consts floating around is kind of an eye sore, but if there's no other way for this, I'll manage.
  20. @sleepy_sealion That's how you override a function (people often refer to it as aliasing but it isn't really).

    I mean, you don't have to use const? You could declare some of them with var, just to mix it up (actually, I don't think I've ever looked in a plugin that used const. Not that it matters).