Ir para conteúdo

rnicson

Members
  • Total de itens

    9
  • Registro em

  • Última visita

Reputação

0 Comum

Sobre rnicson

  1. @Omar~ Verifiquei que passando o valor da variável lineCount dessa forma. document.getElementById("lineCount").innerHTML = lineCount; Eu consigo pegar o valor no outro arquivo assim <pre id="lineCount"></pre> Isso faz com que exibe normalmente o valor correto,porém tem alguma forma de inserir o valor de <pre id=""> em uma variável? Eu tentei usar o var count = document.getElementById("lineCount"); Mas não está funcionando,isso já solucionava meu problema.
  2. Omar com o uso do cookie funciona a leitura da variável em outro arquivo mas não está servindo por conta da exclusão do cookie,ele leva um tempo para excluir e quando atualiza a página pela primeira vez ainda não excluiu,apenas na segunda vez. Isso já iria trazer um resultado não correto. Eu tentei usar da forma que você mandou mas me trouxe o valor undefined ainda. segue abaixo o código que fiz. BlocklyDialogs.congratulations = function() { // Add the user's code. if (BlocklyGames.workspace) { var linesText = document.getElementById('dialogLinesText'); linesText.textContent = ''; // Line produces warning when compiling Puzzle since there is no JavaScript // generator. But this function is never called in Puzzle, so no matter. var code = Blockly.JavaScript.workspaceToCode(BlocklyGames.workspace); code = BlocklyInterface.stripCode(code); var noComments = code.replace(/\/\/[^\n]*/g, ''); // Inline comments. noComments = noComments.replace(/\/\*.*\*\//g, ''); /* Block comments. */ noComments = noComments.replace(/[ \t]+\n/g, '\n'); // Trailing spaces. noComments = noComments.replace(/\n+/g, '\n'); // Blank lines. noComments = noComments.trim(); this.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; } linesText.appendChild(document.createTextNode(text)); } }; BlocklyDialogs.congratulations.prototype.Publico = function(){ return this.lineCount; } var obj = new BlocklyDialogs.congratulations(); var count = obj.Publico();
  3. Boa tarde Estou com um problema para passar valores de uma variável dentro de uma função pra fora pois preciso usar em outro arquivo. Eu consegui passar os valores dela usando localStorage.setItem('lineCount) dentro da função e recuperando fora com getItem,mas isso não me serve pois está sendo criado cookies e quando eu retorno a fase do game para fazer novamente ele não me traz o valor novo e sim o anterior,a não ser que eu de um CTRL+R para limpar o cache. Tentei também criar o cookie e pegar após isso excluir usando removeItem mas parece que ele está excluindo antes de pegar com isso não me exibe valor nenhum. Eu preciso que o valor da variável seja lido de fora da função mas sempre está retornando undefined todos os valores de variáveis que estão dentro dessa função. Já tentei retirar o var,já tentei usar o window. Mas não funciona. BlocklyDialogs.congratulations = function() { var content = document.getElementById('dialogDone'); // Add the user's code. if (BlocklyGames.workspace) { var linesText = document.getElementById('dialogLinesText'); linesText.textContent = ''; // Line produces warning when compiling Puzzle since there is no JavaScript // generator. But this function is never called in Puzzle, so no matter. var code = Blockly.JavaScript.workspaceToCode(BlocklyGames.workspace); code = BlocklyInterface.stripCode(code); var noComments = code.replace(/\/\/[^\n]*/g, ''); // Inline comments. noComments = noComments.replace(/\/\*.*\*\//g, ''); /* Block comments. */ noComments = noComments.replace(/[ \t]+\n/g, '\n'); // Trailing spaces. noComments = noComments.replace(/\n+/g, '\n'); // Blank lines. noComments = noComments.trim(); var lineCount = noComments.split('\n').length; variavel_global = 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)); } if (BlocklyGames.LEVEL < BlocklyGames.MAX_LEVEL) { var text = BlocklyGames.getMsg('Games_nextLevel') .replace('%1', String(BlocklyGames.LEVEL + 1)); } else { var text = BlocklyGames.getMsg('Games_finalLevel'); } var cancel = document.getElementById('doneCancel'); cancel.addEventListener('click', BlocklyDialogs.hideDialog, true); cancel.addEventListener('touchend', BlocklyDialogs.hideDialog, true); var ok = document.getElementById('doneOk'); ok.addEventListener('click', BlocklyInterface.nextLevel, true); ok.addEventListener('touchend', BlocklyInterface.nextLevel, true); BlocklyDialogs.showDialog(content, null, false, true, style, function() { document.body.removeEventListener('keydown', BlocklyDialogs.congratulationsKeyDown, true); }); document.body.addEventListener('keydown', BlocklyDialogs.congratulationsKeyDown, true); document.getElementById('dialogDoneText').textContent = text; }; var line = variavel_global;
×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.