Own distinct variables

Discussion in 'Learning Javascript' started by Milena, Nov 10, 2015.

  1. Milena

    Milena The woman of many questions Veteran

    Messages:
    1,282
    Likes Received:
    106
    Location:
    Ireland
    First Language:
    Irish
    Primarily Uses:
    N/A
    I want to declare my own variables. In ace, we can do this via Modules. How can I make this in js so when I call certain variables, I can just say for example:

    var overdrive_meter_start = Milena.overdrive_value;

    and so on? I want this to be the variables that would receive the values from the params.

    In general, how can you make something like this? is there a way to implement imported = {} as well?
     
    #1
  2. Zalerinian

    Zalerinian Jack of all Errors Veteran

    Messages:
    4,695
    Likes Received:
    921
    Location:
    The Internet.
    First Language:
    English
    Primarily Uses:
    N/A
    Yes, we're able to do that like this:

    Imported = Imported || {};Milena = Milena || {};Milena.whatever = "something";Personally, I prefer to keep all my scripts in separate areas of my 'module', like so:

    Zale = Zale || {};Zale.Plugin = {};Zale.Plugin.Variable = "Something";This way, I can use the same variable name for separate scripts, in the event that they overlap. It also lets me easily check the variables another plugin has set in a loop or something similar.
     
    #2
    babykgar likes this.
  3. Milena

    Milena The woman of many questions Veteran

    Messages:
    1,282
    Likes Received:
    106
    Location:
    Ireland
    First Language:
    Irish
    Primarily Uses:
    N/A
    If I understand correctly, does that code also applies the same in this manner?

    Code:
    var Imported = Imported || {};Imported.BasicMenuPlus = true;var Milena = Milena || {};Milena.params = PluginManager.parameters('Basic Menu Plus'); 
     
    #3
  4. Ramiro

    Ramiro Now with an army of Mecha-Ralphs! Veteran

    Messages:
    860
    Likes Received:
    366
    Location:
    Argentina
    First Language:
    Spanish
    Yes, the only difference is than You are using BasicMenuPlas without using Milena first.

    You may use:

    Milena.BasicMenuPlus = {};Milena.BasicMenuPlus.params = PluginManager.parameters('Basic Menu Plus');Because that way you don't have to worry about the params value if you make another script later.
     
    #4
    Milena likes this.
  5. DarknessFalls

    DarknessFalls Rpg Maker Jesus - JS Dev. Veteran

    Messages:
    1,393
    Likes Received:
    208
    First Language:
    English
    One small thing, dont use snake case, all of Javascript is camelCase. Its the convention.
     
    #5
  6. Zalerinian

    Zalerinian Jack of all Errors Veteran

    Messages:
    4,695
    Likes Received:
    921
    Location:
    The Internet.
    First Language:
    English
    Primarily Uses:
    N/A
    Conventions aren't requirements. If you like it one way, we can recommend the other, but we can't force you into it. We can only be bigots about it.
     
    #6
  7. Ramiro

    Ramiro Now with an army of Mecha-Ralphs! Veteran

    Messages:
    860
    Likes Received:
    366
    Location:
    Argentina
    First Language:
    Spanish
    except for class names, module names, and constants... ya' know.

    A module cound be considered a singleton class, and classes uses the first letter in uppercase, right?... So first letter upper case for singleton classes :p
     
    #7

Share This Page