Skip to main content
abeb6401
Participating Frequently
February 15, 2018
Answered

csInterface.evalScript not working correctly

  • February 15, 2018
  • 1 reply
  • 1201 views

Hi guys. I am pretty much stomped on this one. I am sure I'm making a mistake but I can't see it. Maybe more eyes will help.

Here's what is happening:

I get ad alert from LogRead JSX function on startup which is blank. This works just fine. The second time on a triggered event in the main.js it does not alert which means it's not working, nothing happens

Here's the code snippets:

MAIN.JS - ON START UP

csInterface.evalScript('LogRead(\'\',' + logfilepathname + ')');

HOSTSCRIPT.JSX

//save a text file or write new data

function LogRead(newfiledata,filepathname){

    //read data

   alert(newfiledata);

    var vfiledataread = FileDataRead(filepathname);

    if(vfiledataread == ""){

        //create settings file if not created

        FileDataCreate("theme: Default__",filepathname,"w"); 

    };

 

    if(newfiledata > ""){

        //write update new data to file

        FileDataCreate(newfiledata,filepathname,"e");        

    };

};

MAIN.JS - ON EVENT TRIGGER

csInterface.evalScript('LogRead(' + newstreamdata  + ',' + logfilepathname + ')');

Advice appreciated, thanks!

This topic has been closed for replies.
Correct answer Trevor:

You look to me like you are majorly messing up your quotes in MAIN.JS

Either use the old style

csInterface.evalScript('LogRead("' + newstreamdata  + '", "' + logfilepathname + '")');

Or if working from CC2015 or on some apps even earlier use in the JS file

csInterface.evalScript(`LogRead("${newstreamdata}", "${logfilepathname}")`);

1 reply

Trevor:
Trevor:Correct answer
Legend
February 15, 2018

You look to me like you are majorly messing up your quotes in MAIN.JS

Either use the old style

csInterface.evalScript('LogRead("' + newstreamdata  + '", "' + logfilepathname + '")');

Or if working from CC2015 or on some apps even earlier use in the JS file

csInterface.evalScript(`LogRead("${newstreamdata}", "${logfilepathname}")`);

abeb6401
abeb6401Author
Participating Frequently
February 15, 2018

Both didn't work but that was not the problem. I added the text to the variable and found the issue. The string newline in the newstreamdata was causing a problem. It read from a file which had "newlines" (\n) and it didn't work. I remove the newline spaces from the file and it works. My original code works as well.

Thanks for your help, it helped with my stream of thought! Appreciated your help!