Trying to add lunatic mode to a plugin

I am trying to add lunatic mode into one of my plugins but doesn't work and I can't find why. I'm wondering if someone can help me.


First I declare how to put lines inside an empty _customreq.


var args = content.split(" ");
if (args[0].toLowerCase() == "customreq:") {
        _customreq = _customreq + content.substring(10) + ' ';
}


Then I place a check if _customreq isn't empty.


if (_customreq != '') {
    var custom = true;
    eval(_customreq);
    return custom;
}


And when I place a code like this:


customreq: custom = false;


It still gives "true" no matter what code I place. I can't find where is the problem.


Does anyone know why?


Can someone solve my problem?
Use an implicit identity op (===), so you're making an implicit type conversion. 


Looks like you want to convert a string to Boolean. Implicitly, any non-empty string converted to boolean will be true.
First, "lunatic mode" is not a technical term, so you'll have to explain exactly, what you want to achieve. Also, i would use a regex to read tags, instead of splitting at spaces and dealing with exact word lengths, which is way more prone to errors.


I'll suggest creating a complete demo plugin, that only deals with what you want to achieve (shouldn't be longer, than a few dozen lines) and make that work, before trying to incorporate a functionality into a bigger one.
@ロリ先輩


It uses eval function so implicit identity op isn't needed.


@Iavra


With "lunatic mode" I mean the posibility to inyect javascript code inside a comment to make a result. I am trying to make something like Yanfly does.


My plugin gives a great flexibility to event conditions but I want to enhace this even more by adding lunatic mode. And when done I'll add next feature.


Basically, I want to learn how to add this mode to give extra versatility for anyone who want to use my plugins.


Can you suggest me what regexp would you use? Thanks.
I just tried this in console:


var str = "<tag>test = true</tag>";
var test = false;
eval(/<tag>(.*?)<\/tag>/.exec(str)[1]);


Obviously, you'll need to split up the last line, because you can't be sure, that the tag you are looking for isn't even present (exec will return null, if there was no match).
I use comments in pagelist to add conditions and If needed it can be concatenated.


As example:


customreq: if (($game_variables.value(7) - $game_variables.value(15)) > $game_variables.value(1)) {
custom = false;
}

Code:
customreq: custom = custom XOR $game_switches.value(9);


It sould concatenate codes from both comments into a string, then when it checks if page mets conditions it executes code from string.

Original thread: https://forums.rpgmakerweb.com/threads/trying-to-add-lunatic-mode-to-a-plugin.57020/