Indie Dev

Hello Guest!. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, sell your games, upload content, as well as connect with other members through your own private inbox!

[Scripting] Imported

Status
Not open for further replies.

LTN Games

Master Mind
Resource Team
Xy$
0.01
I notice in Yanfly's plugins he puts
JavaScript:
var Imported = Imported || {};Imported.YEP_VictoryAftermath = true;
I am curious if this is a good practice? I'm assuming it's great for compatibility reasons, considering I've recently had to make one of my plugins compatible with Yanfly's Victory Aftermath and when I did this I did a conditional
Code:
 if(Imported.YEP_VictoryAfterMath)
to check if it's a plugin being used by the player and then proceeding to do rest of my code. My question's are, is it a good idea to do this for my own scripts or is
Code:
LTN = LTN || {}
good enough, and can I do the same Imported if statement for all scripts?
 

eivl

Local Hero
Xy$
0.00
This is a practice from Ruby and it is not needed in JS.

You can access the plugin manager to see what is loaded.

Using Namespacing is a topic beyond normal discussion, but i would have people consider stopp using the imported namespace and only use your own dev bane space, like LTN
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
Okay good, because I did all my scripts with my dev bane space LTN, i've pretty much been following the methods you use in your scripts, in fact I look at most of your scripts for reference. The only thing I notice different with your scripts and other Authors I have looked at is the anonymous functions that I have no clue why and how I should go about using those. Anyways Now I'm curious if and how one would do compatibility checks to see if the plugin is there in the plugin manager? For |Yanflys vistory aftermath he uses the dev namespace Yanfly.VA so would I just do a check for that? Would I do it like this?
JavaScript:
if(Yanfly.VA){
// Do something
}
 

eivl

Local Hero
Xy$
0.00
Yes if VA is true you can do that check.
For some info about the function wrapping i have written about if before so i will not elaborate so much, but the TLDR version is when you use it you are forcing it to run automaticly. If you want to protect your code you should do it. If you do not know if you should use it, then you should.

I might write a lengthy post about this later, just to clearify.
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
Thank you for the reply Eivl, as always you help a ton. I'm going to focus on reading up on anonymous functions to get a better idea of using it and start implementing it's use in my plugins before I release them. Again thank you :D
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
So I read the link you suggested as well a few discussions on another site about them, I still don't have a full understanding of it and I don't quite understand why I would want to do this. I noticed in Galv's plugins he puts his plugin parameters inside an anonymous function, and I understand that this will keep it protected from other people trampling all over it but why should I care? I mean how often will I run into an issue with someone accessing my plugin parameters from their script by using the same namespace as me, LTN.Param. Unless of course there is a different reason for doing this that I don't quite understand. Either way I'll keep reading and looking at other scripts that use them to understand them a bit more.
 

Boy Who Codes

Praised Adventurer
Xy$
0.00
It's like having your own module. I do that on my code. The Imported is not necessary. An example:

Code:
var SOUL_MV = SOUL_MV || {};
this means that I can place any object, parameter or a variable in this case. To put it simply, it's like a container where you put things up. This is necessary if you don't want the same variables with the same name getting accessed. There are other reasons for this practice, you can read it on javascript sites.

Then, whenever I do want to add a new variable from it, I'd go:

Code:
SOUL_MV.action = 4;
The variable action is now stored on SOUL_MV. If you want to make a sub on the SOUL_MV, you will do something like this:

Code:
SOUL_MV.VA = {};
So whenever you store a variable on it, you will do something like:

Code:
SOUL_MV.VA.actionPoses = 16;
If you want to check if VA is existing:

Code:
if (SOUL_MV.VA){
// put stuff here
}
What the if statement is checking is if SOUL_MV.VA is true, or is existing. Normally, the if statement there is looking for either true or false value in this case.
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
If I could mark two Best Answers I would do so lol. Soul your explanation for the module is really good, I am already used to doing the module style as you do and I would not be able to do it any other way lol. Anyways thank you all for the help. I will be opening up a new discussion soon about anonymous functions.

I will be closing this topic now if for some reason you would like it re-opened please report the post.
 
Status
Not open for further replies.
Top