SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
427
Reaction score
174
First Language
Dutch
Primarily Uses
RMMV
"use strict";myaddon.prototype.initialize = function(){  gregregregnejrngrejgnberugiergre = 'rewrwe'; // << some pc's crash here, others don't  dewrewt4gredehgsedr= 'jytjthrs'; // << some pc's crash here, others don't  liiofewhfuiewbfewfkegre= 'fwesfew'; // << some pc's crash here, others don't  x = '3'; // << some pc's crash here, others don't};The above runs fine on some computers, but on others you get the error: gregregregnejrngrejgnberugiergre  is not defined.

Am I missing something or is the only way to get Javascript to be more strict bugged/unreliable?
 
Last edited by a moderator:

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,871
First Language
English
It's probably preventing you from accidentally declaring global variables in a method.

This will probably work:

Code:
"use strict";var  gregregregnejrngrejgnberugiergre;myaddon.prototype.initialize = function(){  gregregregnejrngrejgnberugiergre = 'rewrwe';  dewrewt4gredehgsedr= 'jytjthrs';  liiofewhfuiewbfewfkegre= 'fwesfew';  x = '3';};
I don't know, I don't use strict mode lol
 
Last edited by a moderator:

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,699
Reaction score
939
First Language
English
Primarily Uses
N/A
You need to define your variables with 'var'. Strict mode does not allow for variables that aren't defined as 'var'. Strict mode is seeing those variables as undefined, as you never declared them using 'var', so it is stopping, and telling you you're using a variable you never created, and thus is likely a mispelling.
 

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
427
Reaction score
174
First Language
Dutch
Primarily Uses
RMMV
You need to define your variables with 'var'. Strict mode does not allow for variables that aren't defined as 'var'. Strict mode is seeing those variables as undefined, as you never declared them using 'var', so it is stopping, and telling you you're using a variable you never created, and thus is likely a mispelling.
I don't think you understood my original post. The whole point is that the above code does NOT generate any warnings, errors and doesn't crash on my PC. It should but it does not.

Strict mode does not allow for variables that aren't defined as 'var'
My PC does allow it even in strict mode. Don't know why.

So strict-mode on my PC (and maybe on other PC's as well) seems not to work. When I try it on a website with the javascript-tags, it works.

But I can still use variables without the var-keyword without a crash, without any errors in the console. Undefined global ones however do seem to raise an error (in the console only). But undefined local variables still work perfectly while they should not.

According to w3schools:

"use strict";myFunction();function myFunction() { y = 3.14; // This will also cause an error (y is not defined)}But also that works just fine for me in strict mode. The above raises no error nothing. But again if I try it on a website, it DOES work, if I try it offline in my rpg maker mv, it does not work because it raises no error whatsoever...

Here is the problem:

I code in strict-mode. All seems well, no crash nothing. I release my script and other people get errors because I forgot some var-keywords... I do not understand why they get crashes and my pc does not. I do suspect the whole strict-mode to be unreliable&bugged. And unless I figure out why this happens, I can't use strict-mode.
 
Last edited by a moderator:

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,699
Reaction score
939
First Language
English
Primarily Uses
N/A
What browser are you using? Since it's up to the browser to enable strict mode, it'll be the browser that's broken.
 

kentaromiura

Veteran
Veteran
Joined
Nov 1, 2015
Messages
46
Reaction score
26
First Language
English
Primarily Uses
Strict mode is a tool for the developer, when you're writing your code it will notify you that something is wrong so you can 'fix' your code,

the fixed code 99% of the times work as it is on older browsers not supporting strict mode,

there are some exceptions, as strict mode changes the way javascript is interpreted and so the behaviour in older browsers

so this code, for example will not run the same:

(function(){ "use strict"; try { delete Object.prototype; // throws a TypeError in a strict mode enabled browser } catch(e) { console.log('this log will never show in a browser that does not support Strict mode'); }})()imho we have better tools nowadays (eg http://jshint.com/) to rely on to catch all the cases that 'use strict' catches and more.
 

kentaromiura

Veteran
Veteran
Joined
Nov 1, 2015
Messages
46
Reaction score
26
First Language
English
Primarily Uses
Here is the problem:

I code in strict-mode. All seems well, no crash nothing. I release my script and other people get errors because I forgot some var-keywords... I do not understand why they get crashes and my pc does not. I do suspect the whole strict-mode to be unreliable&bugged. And unless I figure out why this happens, I can't use strict-mode.
are you opening your console? Are you sure there's nothing there?
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
41,871
Reaction score
14,522
First Language
English
Primarily Uses
RMMV
kentaromiura, please avoid double posting, as it is against the forum rules. You can review our forum rules here. Thank you.


If you want to reply to several people at once, please use the MultiQuote button. If you just want to add to a previous post, use the Edit button. This saves you from double posting (posting several times in a row).
 

DarknessFalls

Rpg Maker Jesus - JS Dev.
Veteran
Joined
Jun 7, 2013
Messages
1,393
Reaction score
210
First Language
English
"use strict";myaddon.prototype.initialize = function(){  gregregregnejrngrejgnberugiergre = 'rewrwe'; // << some pc's crash here, others don't  dewrewt4gredehgsedr= 'jytjthrs'; // << some pc's crash here, others don't  liiofewhfuiewbfewfkegre= 'fwesfew'; // << some pc's crash here, others don't  x = '3'; // << some pc's crash here, others don't};The above runs fine on some computers, but on others you get the error: gregregregnejrngrejgnberugiergre  is not defined.

Am I missing something or is the only way to get Javascript to be more strict bugged/unreliable?

Needs to be written:

myaddon.prototype.initialize = function(){ var gregregregnejrngrejgnberugiergre = 'rewrwe'; // << some pc's crash here, others don't var dewrewt4gredehgsedr= 'jytjthrs'; // << some pc's crash here, others don't var liiofewhfuiewbfewfkegre= 'fwesfew'; // << some pc's crash here, others don't var x = '3'; // << some pc's crash here, others don't};// NO GLOBAL VARIABLES WHAT SO EVER!!! :)
 

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
427
Reaction score
174
First Language
Dutch
Primarily Uses
RMMV
What browser are you using? Since it's up to the browser to enable strict mode, it'll be the browser that's broken.
Firefox v42.0. But Firefox does generate an error for me in the console so FireFox is not the one being broken. RPG Maker MV is the one for me not working reliably in strict mode.

imho we have better tools nowadays (eg http://jshint.com/) to rely on to catch all the cases that 'use strict' catches and more.
Thanks I didn't know about this one yet. This site seems nice for testing stuff. Sadly it does throw a TON of errors because of "$gamePlayer, Scene_Map, and all the other buildin RM-classes are undefined of course because the site does not know about those. Still a very nice site that helped me track down a lot of mistakes now that my strict mode is unreliable :) .

are you opening your console? Are you sure there's nothing there?
Checked multiple times, nothing there. Completely empty even with the broken code I posted above like gregregregnejrngrejgnberugiergre = 'rewrwe'; (inside a function). No errors, no warnings, no crash.

Is there some option in RPG Maker maybe that I missed? I mean, just like a browser I suppose RPG Maker does have some kind of internal interpreter or something to run now? Is that one fully compatible with strict mode? I guess it is though.

But the strict mode does seem to work for my dash stamina script, but it does not work for my minimap script. Is it possible that some kind of other code/command can mess up the strict mode?

http://pastebin.com/Q9AKJ1DXhttp://pastebin.com/Q9AKJ1DX

//Lines 1630 & 1632 generate no error for me in strict mode:Scene_Map.prototype.createMinimapWindow = function(minimapType){        x = 0; // << no error for me, does for other people        if (Silv.Minimap.WindowHorizontalAlignment == 'right') { x = Graphics.width - Silv.Minimap.WindowWidth; }        y = 0; // << no error for me, does for other people...It does for other people. I also tested using other undeclared variables in the initialize (starting at line 712). Again nothing, no error nothing. I try the same thing in a browser, and boom I get errors from the strict mode. So something must be really wrong here regarding either strict mode or my pc.

When deploying the code for IOS and opening it in firefox (After disabling security.fileuri.strict_origin_policy) it shows me this error:

ReferenceErrorrequire is not defined
From this code:

function minimapImageExists(filename){ var fullPath = minimapFolderPath() + filename; var fs = require('fs'); // <<< ios doesn't like this, PC however has no problem with it. However, I tested this by opening it in FireFox. Not sure if that is good. return fs.existsSync(fullPath);}which is even worse... The errors differ per platform for me... This one is not even related to strict-mode. I thought RPG Maker MV is :"write code once, deploy to PC, mac os, android/ios".

Does RPG Maker support 'compiler directives' like #if ios, or #if pc so I can write code specific for a platform? Or am I forced to write different versions of the same script for each platform?

Or should I just NOT open RM-ios-deployed packages in FireFox or does FireFox somehow block this file-checking-function?
 
Last edited by a moderator:

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,699
Reaction score
939
First Language
English
Primarily Uses
N/A
When deploying the code for IOS and opening it in firefox (After disabling security.fileuri.strict_origin_policy) it shows me this error:

From this code:

function minimapImageExists(filename){ var fullPath = minimapFolderPath() + filename; var fs = require('fs'); // <<< ios doesn't like this, PC however has no problem with it. However, I tested this by opening it in FireFox. Not sure if that is good. return fs.existsSync(fullPath);}which is even worse... The errors differ per platform for me... This one is not even related to strict-mode. I thought RPG Maker MV is :"write code once, deploy to PC, mac os, android/ios".

Does RPG Maker support 'compiler directives' like #if ios, or #if pc so I can write code specific for a platform? Or am I forced to write different versions of the same script for each platform?

Or should I just NOT open RM-ios-deployed packages in FireFox or does FireFox somehow block this file-checking-function?
It is write code once, deploy to multiple platforms. However, when you use platform-dependant code like NodeJS' fs API, then you're restricting where you can use your code. If you want to check what device you're on, check the Utils class, it has a few functions to detect what you're running on. isNwjs detects if it's on the desktop clients.

Is there some option in RPG Maker maybe that I missed? I mean, just like a browser I suppose RPG Maker does have some kind of internal interpreter or something to run now? Is that one fully compatible with strict mode? I guess it is though.

But the strict mode does seem to work for my dash stamina script, but it does not work for my minimap script. Is it possible that some kind of other code/command can mess up the strict mode?

http://pastebin.com/Q9AKJ1DXhttp://pastebin.com/Q9AKJ1DX

//Lines 1630 & 1632 generate no error for me in strict mode:Scene_Map.prototype.createMinimapWindow = function(minimapType){        x = 0; // << no error for me, does for other people        if (Silv.Minimap.WindowHorizontalAlignment == 'right') { x = Graphics.width - Silv.Minimap.WindowWidth; }        y = 0; // << no error for me, does for other people...It does for other people. I also tested using other undeclared variables in the initialize (starting at line 712). Again nothing, no error nothing. I try the same thing in a browser, and boom I get errors from the strict mode. So something must be really wrong here regarding either strict mode or my pc.
RPG Maker didn't create their own web browser, that would have been incredibly stupid and a waste of time. They're using a version of Chrome, which does support strict mode, so everything should work fine. If it's not working fine for you, then it's probably something with your computer or something, but I've yet to get issues regarding it at all. If the issue persists, perhaps try to proof-read your code to make sure you include stuff like "var".
 

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
427
Reaction score
174
First Language
Dutch
Primarily Uses
RMMV
Did you wrap your whole plugin in an anonymous function, as you should to prevent leaking variables in the public scope? If not, your "use strict" might have been ignored, because the base scripts don't use it.
That seemed to be the problem. The 'use strict'; command (or whatever it's called) has it's own scope. It does not seem to apply to anonymous functions when declared outside of it. But it does apply to other functions. So I have to declare it AGAIN inside that anonymous-function. Changing that made it work on my PC (now crashes for undefined variables as it should).

However, because the behavior of this strict-mode seems to differ per computer and browser (only for RPG Maker...), I still rather not use it at all. Or maybe use it while developing and then out-comment it for the real thing. I still think something is bugged somewhere in the internal RPG Maker code or the Chrome-interpreter they use. Outside of RPG Maker I does work fine.

If I try the code below in a browser, it works. I try it in RPG Maker, it bugs...

"use strict";(function(){ gregerger = 'gergwrgrgre';})();So I think this is a RPG Maker bug.

But for my PC this one DOES work:

(function(){ "use strict"; gregerger = 'gergwrgrgre';})();Ugh...

Can I report possible RPG Maker bugs somewhere so they fix it? 90% sure something is bugging and it's not my code. The other 10% is because it could be some super rare exception in Javascript that is not documented anywhere on the web. I don't think it's my PC.
 
Last edited by a moderator:

DarknessFalls

Rpg Maker Jesus - JS Dev.
Veteran
Joined
Jun 7, 2013
Messages
1,393
Reaction score
210
First Language
English
Stop using global variables.

variableName = 'value';fails because its global and strict mode doesn't allow for global variables.

var variableName = 'value';will never fail. Regardless what computer you are on.

This is NOT bug with MV
 
Last edited by a moderator:

estriole

Veteran
Veteran
Joined
Jun 27, 2012
Messages
1,448
Reaction score
695
First Language
indonesian
Stop using global variables.

variableName = 'value';fails because its global and strict mode doesn't allow for global variables.

var variableName = 'value';will never fail. Regardless what computer you are on.

This is NOT bug with MV
wait... so global variable didn't get affected by strict mode??? really??

he said that WITH strict mode... he expect that code to crash... but it didn't in his computer.

while in same time in some other computer it crash.

so i think it's a bug in MV.

unless global variable didn't get affected by strict mode... which i think it's absurd design for JS if it's like that.

but it still crash in other people PC according to him. so... which one is correct???
 

Galv

Veteran
Veteran
Joined
Oct 1, 2012
Messages
1,349
Reaction score
1,632
First Language
English
Primarily Uses
RMMZ
I believe the "use strict"; code need to be the first command in an execution context. So if you put that outside of an immediately executed anonymous function in your plugin, it wouldn't register it as use strict for the global execution context as there was plugin code run before it in that context.
 

DarknessFalls

Rpg Maker Jesus - JS Dev.
Veteran
Joined
Jun 7, 2013
Messages
1,393
Reaction score
210
First Language
English
I believe the "use strict"; code need to be the first command in an execution context. So if you put that outside of an immediately executed anonymous function in your plugin, it wouldn't register it as use strict for the global execution context as there was plugin code run before it in that context.
this is correct. 

'use strict';is only accounted for in the context of scope
 

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
427
Reaction score
174
First Language
Dutch
Primarily Uses
RMMV
@DarknessFalls:

I believe you are missing the whole point of this topic by far.

Stop using global variables.

variableName = 'value';fails because its global and strict mode doesn't allow for global variables.
Code:
var variableName = 'value';
will never fail. Regardless what computer you are on.
 
This is NOT bug with MV
No hard feelings and I thank you for the friendly advise. But I do not need a (2nd) lesson on "not using global variables" or the var-keyword. If you read my post you saw that:

Undefined global ones however do seem to raise an error (in the console only). But undefined local variables still work perfectly while they should not.
I know that I must use "var".

The whole point about this topic (as Estriole mentioned) is that it does not crash when I expect it (and it should) to crash. Because if it doesn't crash on my PC, I think the code is fine even though I may have missed a var-keyword and then on another computer (or on the same computer but different platform) it will crash instantly all over the place... THAT is the problem. Especially if you release a game.
Not to mention that most of the snippets posted here are purely for debugging this strict-mode. I simply had to test global variables too, good thing I did because they produce different results in strict-mode, which they should not.

So I WANT it to crash but it doesn't. And it SHOULD crash according to all the info I can find regarding strict-mode. And it works fine anywhere but in RPG Maker for me.
 
I believe the "use strict"; code need to be the first command in an execution context. So if you put that outside of an immediately executed anonymous function in your plugin, it wouldn't register it as use strict for the global execution context as there was plugin code run before it in that context.
At first I was in doubt about this too. However, the moment I tested this in a browser, the browser did not require this to be the first command in an execution context and strict-mode worked fine. Nor is this mentioned anywhere on the web that I could find. It simply works for the entire 'snippet'. Therefor this can't be the reason for this 'unreliable behavior'. I still suspect a RPG Maker Bug or at least some hidden mechanic.

Ah I got ninja-ed :p .

Anyway:

this is correct. 

'use strict';is only accounted for in the context of scope
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode

It seems that strict-mode can be activated on a function by function basis. In fact, when I enable strict-mode globally, it could also enable strict-mode for other scripts. Which is not good. But this is only from the MSDN reference which has more functions and is slightly a different Javascript than the one we use I think. At least they have more functions in their JS-distribution so this info may not be accurate.

But strict-mode having a scope would make sense and I already tested this to be the case in one of my previous posts. But even then this reason still has 2 problems:

- Why does FireFox apply it to anonymous functions as well and RPG Maker not with the exact same code? Why does only RPG Maker see it as a different scope? Does RPG Maker do something special with anonymous functions that I'm not aware of? And why can the same code yield different results per platform (or per PC)?

- It should be inside the scope anyway if I enable strict-mode in a global scope. But it is not (or bugs whatever). Unless again ofcourse RPG Maker does something in the internal code that I'm not aware of to change this.

I found this in the RM-code:

PluginManager.loadScript = function(name) { var url = this._path + name; var script = document.createElement('script'); script.type = 'text/javascript'; script.src = url; script.async = false; script.onerror = this.onError.bind(this); script._url = url; document.body.appendChild(script); /// <<<<};So it seems to concatenate the whole thing. This alone, aside from it's weird behavior already, is sadly already enough reason not to use strict-mode on a global scope (unless RM would force us to). I would have loved to see all of RPG Maker in strict-mode. But for some reason the devs decided not too (what was the reason not to btw?). You can of course still use it inside functions. But even then it may or may not work as you expect...

For now I use this site that Kenta recommended me: http://jshint.com/  everytime something goes wrong or before I release a new version of something I copy-paste the whole thing in it, instead of using strict-mode. It's not ideal but at least this is 100% stable so far and does not yield unreliable results.

I should probably test strict-mode more on a function-by-function basis but I just don't care enough anymore. Because something related to strict-mode (in RPG Maker) is bugged anyway so again I rather just stay the hell away from this.
 
Last edited by a moderator:

DarknessFalls

Rpg Maker Jesus - JS Dev.
Veteran
Joined
Jun 7, 2013
Messages
1,393
Reaction score
210
First Language
English
I use babel to compile my code it puts 'use strict'; through out the code and I have never had an issue.
 

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
427
Reaction score
174
First Language
Dutch
Primarily Uses
RMMV
Weird, I tried strict-mode again and now it works properly (same pc). Maybe one of the RPG Maker patches fixed it. I now get errors when undefined variables are used.
 
Last edited by a moderator:

Latest Threads

Latest Posts

Latest Profile Posts

I really lack discipline and find myself far too often giving into or at least seriously considering the temptation to start a new project rather than following through on a WIP that's no longer a shiny and new idea.

Does anyone have any strategies or tricks for making themselves follow through with things instead of doing this? Like that actually work?
I'm starting the "Switches lesson" on Learn MV today, what would you like to learn about them?

Forum statistics

Threads
110,416
Messages
1,053,158
Members
143,486
Latest member
Galbador
Top