While working on coding the game blockly, I encountered a variable named lineCount within the lib-dialog.js file. This variable keeps track of the number of line breaks in the code. By inserting this variable's value using innerHTML, I was able to display the number of lines by creating a div element in the soy.js file (which is where I need to handle the output). However, I require this value in a variable so that I can use it in an if statement like if(lines == 6) { }
// Implementation of user's code.
if (BlocklyGames.workspace) {
var linesText = document.getElementById('dialogLinesText');
linesText.textContent = '';
// The following line causes warnings during Puzzle compilation due to lack of JavaScript generator but is irrelevant for Puzzle.
var code = Blockly.JavaScript.workspaceToCode(BlocklyGames.workspace);
code = BlocklyInterface.stripCode(code);
var noComments = code.replace(/\/\/[^\n]*/g, ''); // Removing inline comments.
noComments = noComments.replace(/\/\*.*\*\//g, ''); /* Removing block comments. */
noComments = noComments.replace(/[ \t]+\n/g, '\n'); // Trimming trailing spaces.
noComments = noComments.replace(/\n+/g, '\n'); // Eliminating blank lines.
noComments = noComments.trim();
var lineCount = noComments.split('\n').length;
var pre = document.getElementById('containerCode');
pre.textContent = code;
if (typeof prettyPrintOne == 'function') {
code = pre.innerHTML;
code = prettyPrintOne(code, 'js');
pre.innerHTML = code;
}
if (lineCount == 1) {
var text = BlocklyGames.getMsg('Games_linesOfCode1');
} else {
var text = BlocklyGames.getMsg('Games_linesOfCode2')
.replace('%1', String(lineCount));
}
linesText.appendChild(document.createTextNode(text));
document.getElementById("contarBloco").innerHTML = lineCount;
var contandoBloco = lineCount;
}
I'm facing difficulties taking the lineCount variable and assigning its value to another js file. Currently, I am only able to insert it into a div using innerHTML.