I get this error on the next line (for the expression var blocks = [];)

<string name="app_name">getbackbreakedblocksmod</string> <string name="code"> var blocks = []; function destroyBlock(x,y,z,a){ var id = getTile(x,y,z); blocks.push({x:x,y:y,z:z,blockid:id});} function procCmd(c){ if(c=='g'){ blocks.forEach(function(block){ setTile(block.x,block.y,block.z,block.blockid); }); } }</string> 

    1 answer 1

    The error says that apostrophes should be escaped by the \ character .

    Obviously the compiler doesn’t like ' in the if(c=='g') , it should be if(c==\'g\') .

    The same problems can be with other characters, like [ , ] , { , } - then they should also be escaped.

    Perhaps it would be better to enclose the entire string in double quotes (then you do not need to escape individual characters):

     <string name="code"> "var blocks = []; function destroyBlock(x,y,z,a){ var id = getTile(x,y,z); blocks.push({x:x,y:y,z:z,blockid:id});} function procCmd(c){ if(c=='g'){ blocks.forEach(function(block){ setTile(block.x,block.y,block.z,block.blockid); }); } }"</string>