Hi guys I saw some people using imported variable....
but I am unsure how to properly use it for MV actually
how do I create them and can use them for make condition?
var Imported = Imported || {};
This will keep the existing variable if it exists, or create a new one with an empty object if it doesn't.
If you don't care about the content of the variable, you should check for "truthiness", that is:
if(Imported.Nio) { ... }This way, the code in brackets will be executed, as long as Imported.Nio is defined and is not:
- null
- 0
- NaN
- '' (empty String)
- false
Spriteset_TitleScreen.prototype.createParticles = function() { if(Imported.EmojiParticles){ if ($emoji.EnableParticles){ this._particles = new Emoji_Particles(); } } };why not like this? if it is not undefined, it will throw the value true, so you should just be checking whether Imported.EmojiParticles is true or not.
edit: sorry apparently i'm wrong 😀 .
I was unsure since Javascript is kinda sh*tty on detecting problem correctly so I avoid to left the system "guessing" what I want because f*ck Javascript can be such a bad interpreter.
Actually, it detects imported variables efficiently. What I did there was just something natural for the scripting language, which I used when I am still using Ruby.
it's depends if you use "use strict" or not I usually not use it but nope JavaScript can be horrible on debugging because it's create variable on the fly and set it automatically on 'undefined' when you bad write a variable...
so no I don't take chance with conditions and unless the variable is already defined I prefer define a clear condition.
Although I know this proceed don't forgot I am also a Ruby Native...so this proceed is natural...
just with JS you just don't take chance because JS != Ruby and JS is having really weird behavior