2

I'm having a bit of fun on https://blockly-games.appspot.com and have got to the last level where you can write full blown javascript (new Date().getTime(); is very handy).

Despite having the console open in Chrome (ctrl-shift-j) I can't seem to write anything to it with console.log("test"); from within the game. When I do I see:

// Starting battle with 2 players.                         compressed.js:420
// [Player] throws an error: Unknown identifier: console   compressed.js:423
// undefined                                               compressed.js:423
// [Player] dies.                                          compressed.js:416

Yet if I type console.log("hmm"); in the console I properly see:

// console.log("hmm"); 
// hmm                                                     VM1038:2 
// undefined

Same story if I try to use alert("test").

I want to debug, but the only forms of output I've found are manipulating the duck and throwing Unknown identifiers. Is there any way out of this sandbox?

Update: How do I print debug messages in the Google Chrome JavaScript Console? has some ideas for restoring console but they don't seem to work in this case.

Update: just to be clear this is what chrome looks like when experiencing this error.

enter image description here

7
  • This is strange. So you are positive that the code gets executed, yes blockly somehow suppresses both console.log and alert? Commented May 14, 2015 at 15:57
  • I'd be curious what happens if you step through alert in debugger. Commented May 14, 2015 at 15:58
  • @ТаняТ. I run other code fine but for some reason blockly has undefined the console so I have no reference to it. I'd love to step through but how exactly would I do that when player.js (my code) doesn't even show up as a file in Chrome's debugger? Commented May 16, 2015 at 3:43
  • This is strange. Why does not it show up in debugger? Does HTML show up in debugger? Why don't you set up breakpoint in html, call your code from embedded (not included) javascript, and go from there? Commented May 16, 2015 at 6:12
  • @ТаняТ. I have no trouble setting and hitting a breakpoint so long as it's in one of the blockly sources (common/boot.js etc). The problem is finding my way into my code (player.js) after that. Can you see a good place to set this breakpoint? I have a suspicion that the closest I can get to it is tracing the interpreter that runs my code. Commented May 16, 2015 at 6:40

1 Answer 1

0

Found a kludgey workaround:

  throw "\nYour message here.";

Displays:

//  [Player] throws an error: Unknown identifier:         compressed.js:423 
// Your message here.                                     
//  undefined                                             compressed.js:423 
//  [Player] dies.                                        compressed.js:416

Killing yourself just to log something may seem harsh but now you can write some snazzy asserts.

function assertTrue(test, message) {
  if (!test) {
    throw message;
  }
}

It works, but Lord knows I wish there was a better way.

Sign up to request clarification or add additional context in comments.

10 Comments

Are you still getting this issue? I can make reference both console.log or alert from my console of Google Chrome either inside the Javascript code.
@Error404 Yes just tried it: "[Player] throws an error: Unknown identifier: console"
@Error404 "[Player] throws an error: Unknown identifier: alert"
Are you trying to do it in a custom example or a Google example? The second link that you provide on the question is broken so I cannot see where are you trying to do that. I am using console.log on my custom example and it works perfectly.
@Error404 I'm doing it in the javascript field the page provides for you to write all your code in. The field that starts off with cannon(0, 70); in it. I've fixed the link. You say it works for you but I can't get it to work on chrome, firefox, or IE. Could you tell me some details about how your getting it to work?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.