tjvr / kurt

Python library for reading/writing MIT's Scratch file format.
https://kurt.tjvr.org
GNU General Public License v3.0
86 stars 24 forks source link

"Set" block not supported #42

Open raulperula opened 7 years ago

raulperula commented 7 years ago

Hi,

I am trying to set the value of a variable but Kurt is throwing an exception telling that this kind of block is not supported in Scratch 2.0.

This is the code:

selection_001

And this is the exception:

Traceback (most recent call last):
  File "scratch2python.py", line 105, in <module>
    p = kurt.Project.load(open_path + sys.argv[1])
  File "/home/raul/workspace/gsoc2017/kurt/kurt/__init__.py", line 282, in load
    project.convert(plugin)
  File "/home/raul/workspace/gsoc2017/kurt/kurt/__init__.py", line 344, in convert
    return list(self._normalize())
  File "/home/raul/workspace/gsoc2017/kurt/kurt/__init__.py", line 517, in _normalize
    script.blocks = map(convert_block, script.blocks)
  File "/home/raul/workspace/gsoc2017/kurt/kurt/__init__.py", line 508, in convert_block
    arg = map(convert_block, arg)
  File "/home/raul/workspace/gsoc2017/kurt/kurt/__init__.py", line 489, in convert_block
    pbt = block.type.convert(self._plugin)
  File "/home/raul/workspace/gsoc2017/kurt/kurt/__init__.py", line 1665, in convert
    raise err
kurt.BlockNotSupported: Scratch 2.0 doesn't have <kurt.BlockType(u"set  to ''" shape='stack')>. Caused by: kurt.Block('setVar:to:', u'laser_data', 
    kurt.Block('Scratch2Robot/laser/frontal'),
)

The "set" blocks are valid in Scratch 2.0 (more info) but Kurt is not loading this kind of blocks for some reason.

CosmicWebServices commented 7 years ago

It may be the block in the set...

tjvr commented 7 years ago

It may be the block in the set...

This seems likely!

raulperula commented 7 years ago

Do you have any idea where we could look for a solution in the code?

raulperula commented 7 years ago

I have solved the problem. It was due to the auto-generated "commands_src" that did not include that kind of blocks (I do not know exactly why).

I have implemented a solution separating the auto-generated file and the "extras" file that contains the extensions and the two commands related to variables.

Once you add the changes from the pull request I could do another with this solution.