Using strings inside mblock extensions code


#1

I was recently making an extensions for mBlock that can be used to write code for Arduino, when I came over this obstacle. I tried to write a function inside the work:"" statement.

It looked like this:

work:“Serial.print(“Hello world”);”

The extensions could not be uploaded, due to the quotation marks around the Hello world string. I tried removing the quotation marks, the extension was sucessfully added, but the program did not work, beacause quotation marks are needed inside C++ code to define a string.

Is there a way to add them in the extensions, without screwing up the code?


#2

Hi,

The extensions are JSON formatted. To place " in a JSON field you have to escape it with a backslash.
Your string should look like:
work:"Serial.print(\"Hello world\");"