Complete Beginner Exploring rpg_windows.js

Discussion in 'Learning Javascript' started by Zizka, Aug 17, 2019.

  1. Restart

    Restart Veteran Veteran

    Messages:
    202
    Likes Received:
    130
    First Language:
    English
    Primarily Uses:
    RMMV
    I think Galv has a plugin that does that
    https://forums.rpgmakerweb.com/index.php?threads/galvs-message-sound-effects.49418/

    so does iavra
    https://forums.rpgmakerweb.com/index.php?threads/iavra-text-sound.49347/

    so you can see how a couple people approached this.
     
    #41
    Zizka likes this.
  2. Zizka

    Zizka Veteran Veteran

    Messages:
    102
    Likes Received:
    22
    First Language:
    English
    Primarily Uses:
    RMMV
    That's great, thank you, I will indeed check how they did it.
     
    #42
  3. Zizka

    Zizka Veteran Veteran

    Messages:
    102
    Likes Received:
    22
    First Language:
    English
    Primarily Uses:
    RMMV
    I'm currently studying classes so I thought it would tie in nicely to what we're discussing here.

    upload_2019-8-22_9-32-10.png
    This reminds me of the .prototype we talked about earlier.

    a) So according to my search on Google:
    upload_2019-8-22_9-35-31.png
    b) 3. is probably what we were talking about with:
    upload_2019-8-22_9-36-10.png
    c) I just realized that in the case above: .prototype is a property while .drawItem is a method. From what I understand, this structure is typical of prototypal instantiation.

    d) In the cons of that instantiation I read:
    upload_2019-8-22_9-40-25.png
    The constructor function is something we also talked about previously with Zevia.

    e) Further into the exercise, there is discussion of the .constructor method which is limited to classes. Doing a quick 'ctrl+F', I find that method used in the windows.js:
    upload_2019-8-22_9-45-2.png
    Image 5
    ...which is cool when you see something you're learning actually used in practice.

    f) The class I had to create in my exercise admittedly looks very different than the classes above:
    upload_2019-8-22_9-52-23.png
    For instance:
    Line 1: I use curved braces after my class declaration while above only use parentheses.
    Line 3: I use .this but there's none in image 5... although it used in a different class:
    upload_2019-8-22_9-55-16.png
    Image 6
    which means we don't always use .this with every class, just some of them.
    Line 1: I don't use the assignment operator while they do in image 6.

    g) So an instance is:
    An instance is an object that contains the property names and methods of a class, but with unique property values.

    What would be considered an example of an instance in rpg_windows.js?
     
    #43
  4. Aloe Guvner

    Aloe Guvner Walrus Veteran

    Messages:
    1,561
    Likes Received:
    978
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    Looks like you're making good progress on learning so I'll just respond to a select few points.
    What you learned in the exercise is using syntax available since 2015 (ES2015 specification) and is preferred by most JS developers. Under the hood, it still uses prototype inheritance, but it's considered a cleaner syntax. Personally I prefer the "class" keyword.

    MV code could be rewritten to use this, like:
    Code:
    class Window_Gold extends Window_Base {
       constructor() {
          super()
       }
       // all the stuff for window gold goes here
    } 
    The MV developers aren't going to do that rewrite because it's literally thousands of lines of code and I doubt they have the time.

    You won't find an example of a window instance in rpg_windows.js. Why? Because that file defines what the windows are. It defines the hierarchy (all windows inherit from Window_Base, the Window_Command inherits from Window_Selectable, etc. etc.). That file defines the properties and methods used by the windows. But that file does not create any instance of windows.

    You would find that in rpg_scenes.js. Take the gold window, where does it appear? What is it a component of?
    It appears in the menu scene. It can also appear in the map scene too.
    So looking at Scene_Menu, you will find a line that's something like:
    Code:
    this._goldWindow = new Window_Gold() 
    Where "this" is referring to the scene. You could describe that relationship as a "contains a" relationship, as in "the menu scene contains a gold window". That pattern is called Composition.
    There's also the "inherits from" relationship as in "the gold window inherits from the base window". That pattern is called Inheritance.

    As you can see, those patterns do not work against each other but worth together to make the menu do stuff.
     
    #44
    Zizka likes this.
  5. Restart

    Restart Veteran Veteran

    Messages:
    202
    Likes Received:
    130
    First Language:
    English
    Primarily Uses:
    RMMV
    in theory since it's a rigidly-defined find-and-replace problem you could automate it, but in practice...
     
    #45
  6. Aloe Guvner

    Aloe Guvner Walrus Veteran

    Messages:
    1,561
    Likes Received:
    978
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    #46
    Zizka likes this.
  7. Zizka

    Zizka Veteran Veteran

    Messages:
    102
    Likes Received:
    22
    First Language:
    English
    Primarily Uses:
    RMMV
    I'm currently studying objects and classes and doing exercises about them. It's fairly exciting to finally be studying something more in context with what I ultimately aim to do.

    I was told about JSON on a different forum which is a subset of Java Script. Is that something I should worry myself with or just I ignore this for now? I'd like to stick with learning about the essentials so I'd only learn about JSON if I absolutely have to.

    I've scrolled through thousands of lines of codes in rpg_windows.js and almost every single entry has the .prototype.

    So out of curiosity I checked rpg_scenes as well and same thing, from what I could tell everything was .prototype.

    Admittedly I could check every single file but I figured I could also ask: are all the .js files or RMMV like that with the .prototype property? Is it because it's the source code that's it's like this?
     
    #47
  8. Poryg

    Poryg Pixie of the Emvee kingdom, Ham of a Hamster Veteran

    Messages:
    3,860
    Likes Received:
    9,674
    Location:
    Czech Republic
    First Language:
    Czech
    Primarily Uses:
    RMMV
    JavaScript Object Notation are simply text files used to store data in object notation, because a file/data with a certain structure is easier to manipulate than a file/data without it. I'd treat it as a convenient naming convention than subset of Javascript for now as most of the time you don't use it (you use it pretty much only when you are dealing with files and most of the time you use only parse and stringify methods).

    Yes, almost everything in rpg_* files is prototype. It was written in ES5 standards and prototype was the only way to do something close to object oriented programming. And we're not going to see it rewritten to ES6, because there's no performance gain from just rewriting it in ES6. You'd need to upgrade it with optimizations, but even though MV needs optimizations like mad, they won't happen, because they reportedly want to keep the engine compatible with as many plugins as possible.
     
    #48
  9. Zizka

    Zizka Veteran Veteran

    Messages:
    102
    Likes Received:
    22
    First Language:
    English
    Primarily Uses:
    RMMV
    Oh I see thanks.

    (By the way, as a slight tangent, I tried watching your tutorials. It's really a shame that the text is so small as I can't see anything. A 2 hours tutorial would be great but I personally can't see what you're writing, even in full screen.)
     
    #49

Share This Page