Question

I do not understand how I keep ending up with "null" after variable is assigned a number.

function evalKayScript(syn){
    coms = extract(syn,"{...}");
    document.write(JSON.stringify(coms));//debug
    for(x in coms){
        ops = extract(coms[x],"(...)");
        com = null; //<-- ***com preset null***
        for(y in funNames){
            if(ops[1] == funNames[y]){
                com = y; //<-- ***com changed to "y"***
            }
        }
        alert(com); <-- alerts given below (first two alerts)
        if(com == null){
            alert("Command ((("+ops[1]+"))) Not Registered!");
            return null;
        }
        exe = funValues[y];
        inputs = execVars(ops[2]);
        inputs = extract(inputs,"[...]");
        for(y in inputs){
            exe.replace(new RegExp("/\(\%"+y+"\%\)/gim"),inputs[y]);
        }
        exe.replace(new RegExp("/\(\%name\%\)/gim"),ops[0]).replace(new RegExp("/\(\%function\%\)/gim"),ops[1]);
        exea = exe;
        if(exe.replace(new RegExp("/\:\:\:javascript/gim"),"")! = exes){ //<-- new invalid ":" error
            eval(exe);
        }else{
            evalKayScript(exe);
        }
    }
}

I do not understand why, variable "com" goes to a number, then back to null... I have setup some error catching in my own form, and i end up with these alerts:

0 //<-- var com
null //<-- ***var com? this makes no sense, how does it go back to null?***
Command ((("(%name%) already exists!"))) Not Registered! //<--caused by if(com == null) This is normal.

Live script at http://jstone88.bugs3.com/kayscript/file1.html, and JS file at http://jstone88.bugs3.com/kayscript/kayscript.js

Was it helpful?

Solution

You aren't using RegExp constructor as it should have been used.

It is like this:

new RegExp("pattern without / at the beginning an end","flags");

/pattern/flags is literal form of writing a regex in js, but it is different in RegExp constructor.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top