Git Product home page Git Product logo

pystage's Introduction

PyStage

Documentation Status

Scratch-like Python programming.

PyStage bridges the gap between Scratch and Python. This module implements all code blocks as available in scratch. With the PyStage command line converter Scratch projects can be easily transferred to Python executable Code. To run your game in Python, PyStage uses PyGame.

test

Demo

Consider the following code. It defines a stage and a sprite on the stage. The functions are code blocks that are associated with events (i.e. connected to a hat block in Scratch) via the corresponding methods.

from pystage.en import Stage

stage = Stage()
stage.add_backdrop("grid")
zombie = stage.add_a_sprite()

def doit(zombie):
    zombie.say("Hello pyStage!")
    for i in range(4):
        zombie.move(10)
        zombie.wait(1)
        zombie.think("This is awesome!")
        zombie.turn_left(90)
        zombie.wait(1)
        zombie.think("")
    zombie.say("Move me around with WASD.")

zombie.when_program_starts(doit)

def right(zombie):
    zombie.change_x_by(10)

def left(zombie):
    zombie.change_x_by(-10)

def up(zombie):
    zombie.change_y_by(10)

def down(zombie):
    zombie.change_y_by(-10)

zombie.when_key_pressed("d", right)
zombie.when_key_pressed("a", left)
zombie.when_key_pressed("w", up)
zombie.when_key_pressed("s", down)

stage.play()

And here is the result:

Demo screen capture

Goals

  • Export your Scratch project to real executable Python code!
  • Helping coding beginners to learn Python "by Scratch".
  • Implementation of scratch blocks in several languages (ideal for kids). As of now en and de.

A quick into video

See our quick intro to PyStage for ScratchCon 2021

Installation

pip install pystage

if doesn't work, try following commands one by one.

pip install wheel
pip install pygame==2.3.0
pip install svglib==1.1.0
pip install reportlab==3.5.67
pip install pystage

Getting started

If you are interested in PyStage and want to get in touch, feel free to join us on our Discord Server.

Currently, only the English API is fully translated, the German API is automatically generated. All other languages will be added when PyStage gets more stable. Get in touch if you want to help maintain a translation.

For the English API, you can start with the following example code:

from pystage.en import Sprite, Stage

stage = Stage()
zombie = stage.add_a_sprite()

def doit(zombie: Sprite):
    for i in range(4):
        zombie.move(10)
        zombie.turn_left(90)
        zombie.wait(1)

zombie.when_program_starts(doit)

stage.play()

Use the autocompletion of your editor to see what methods are available. There are methods for all Scratch blocks bound to your stage and sprite instances. Not all of them work. Motion and Looks is mostly implemented (besides graphics effects), the Pen extension works and most of Sensing should work as well. If you want to know the details, just check the files under src/pystge/core.

The documentation is here: https://pystage.readthedocs.io/en/latest/pystage.en.html


NOTE

Please note this is a pre alpha version. Not all things may work as expected. If so, please contact us or open an issue. Documentation is automatically generated but especially the user-facing block API is still mostly empty.


Import your Scratch projects

Converting a Scratch project to Python code:

  1. Export your Scratch project on the Scratch page. You will get an .sb3 file.
  2. Use our command line converter. Yes, it's unhandy, we will work on it to make things easier.

The base usage is python -m pystage.convert.sb3 <SB3 File> -l en -d <DIRECTORY> The parameters are:

  • -l language of generated python "scratch blocks". In the moment of writing, en and de are available.
  • -d the output directory, defaults to current directory
  • -i print intermediate code representation
  • -s print sb3 project.json
  • -p print python code
  • -v verbose
  • -vv debug mode

Contributors

  • Kai Eckert, Stuttgart Media University
  • Florian Rupp, Stuttgart Media University

pystage's People

Contributors

brandenhusted avatar florianrupp avatar kaiec avatar victornorman avatar zhonglin-niu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pystage's Issues

NameError: name 'self' is not defined

I keep getting this error many times...
Traceback (most recent call last):
File "G:\My Drive\Documents\Pycharm\Goup\main.py", line 24, in
self.when_timer_GREATERTHAN(0.1)
^^^^
NameError: name 'self' is not defined

Translate eror

Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File "C:\Users\yusuf\AppData\Local\Programs\Python\Python311\Lib\site-packages\pystage\convert\sb3.py", line 448, in
project = get_intermediate(data, project_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\yusuf\AppData\Local\Programs\Python\Python311\Lib\site-packages\pystage\convert\sb3.py", line 234, in get_intermediate
block = get_block(b, blocks, target["isStage"])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\yusuf\AppData\Local\Programs\Python\Python311\Lib\site-packages\pystage\convert\sb3.py", line 157, in get_block
res["next"] = get_block(blocks[block["next"]], blocks, stage)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\yusuf\AppData\Local\Programs\Python\Python311\Lib\site-packages\pystage\convert\sb3.py", line 155, in get_block
res["params"][i] = get_block(blocks[value], blocks, stage)
~~~~~~^^^^^^^
KeyError: None

Sound Problem

I've tried everything to get a freakin' sound to play into my program, even reading the docs, but THERE'S NO ACTUAL EXPLANATION, can you PLEASE just show an image or a GIF of it's actual use? It's so hard...

Literally, it just says "play_sound_until_done(name)" but I'm doing that and it's not working

And no, I'm not using an mp3, I tried using a wav, didn't work, and an ogg currently, DOESN'T WORK

Bug when running with Thonny

Might also be a problem with PyCharm or other IDEs that run python internally. In this case they seem to mess with the stdout and stderr like we do...

Traceback (most recent call last):
File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/lib/python3/dist-packages/thonny/plugins/cpython/main.py", line 43, in
MainCPythonBackend(target_cwd).mainloop()
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 72, in mainloop
self._handle_normal_command(msg)
File "/usr/lib/python3/dist-packages/thonny/plugins/cpython/cpython_backend.py", line 253, in _handle_normal_command
self.send_message(real_response)
File "/usr/lib/python3/dist-packages/thonny/plugins/cpython/cpython_backend.py", line 908, in send_message
sys.stdout.flush()
ValueError: I/O operation on closed file.

Backend terminated or disconnected. Use 'Stop/Restart' to restart.

Documentation

  • choose a system for the official documentation. Document for developers how to use it.

NameError: name 'self' is not defined when converted Greeting_Card.sb3

Hi, I was thinking about trying to make a Scratch to Python converter, when I came across your project, and I am very impressed - good job. As you say this is a "pre alpha version" and expect a few issues.
I am keen to see this working, so I tried with the simple "Greetings Card" project, which can be downloaded from here: https://scratch.mit.edu/projects/11806234/editor/

I am running on Windows/10 using Python 3.9.1
I first saved the project as "Greeting_Card.sb3", then
converted it using: python -m pystage.convert.sb3 Greeting_Card.sb3 -l en -d converted
I got these messages during conversion:

Creating project: greeting_card
Exporting to: converted
No API method for sensing_touchingobjectmenu
No API method for sensing_touchingobjectmenu
No API method for looks_changeeffectby
No API method for looks_changeeffectby

A DIR /s of the converted directory reveals:
25/03/2024 14:35 2,961 greeting_card.py
25/03/2024 14:30

images
25/03/2024 14:30 sounds
1 File(s) 2,961 bytes

Directory of ...\converted\images

25/03/2024 14:30 1,381 arrow1.svg
25/03/2024 14:30 1,454 arrow2.svg
25/03/2024 14:30 6,125 backdrop1.svg
25/03/2024 14:30 6,299 backdrop2.svg
25/03/2024 14:30 6,303 backdrop3.svg
25/03/2024 14:30 740 birthday1.svg
25/03/2024 14:30 30,698 cake.svg
25/03/2024 14:30 30,647 cake2.svg
25/03/2024 14:30 736 happy1.svg
25/03/2024 14:30 20,878 penguin1.svg
25/03/2024 14:30 20,956 penguin2.svg
11 File(s) 126,217 bytes

Directory of ...\converted\sounds

25/03/2024 14:30 538,172 happy_birthday.wav
1 File(s) 538,172 bytes

When I tried to run the Python code, I got this error:
File "...\converted\greeting_card.py", line 10
self.play_sound_until_done("happy_birthday")penguin1 = stage.add_a_sprite(None)

I could see that there was missing a new-line between "happy_birthday") and penguin1
so I inserted a new-line and retried.

I encountered several more of these, but when finally all corrected, I got this error:
New costume: backdrop1 -> images/backdrop1.svg
New costume: backdrop2 -> images/backdrop2.svg
New costume: backdrop3 -> images/backdrop3.svg
Traceback (most recent call last):
File "...\converted\greeting_card.py", line 9, in
self.when_backdrop_switches_to("backdrop3")
NameError: name 'self' is not defined

I could not debug further, so I raised this issue.
Please let me know if I have made any mistakes in trying to convert this project, or in my diagnosis, so far?

Use of "self" as first parameter in generated function (not method) is misleading

My little scratch program was converted to having this python function.

def when_program_starts_1(self):
    while True:
        self.move(10.0)
        self.wait(0.1)

This is a function, but uses self as the first parameter, which is kind of a reserved word to be used as the first parameter
for method definitions in classes.

The parameter that is passed in, in this case, is a Sprite object. I would suggest changing "self" to "sprite", which would
also make the code read better:

sprite.move()
sprite.wait()

This is all "In my opinion", of course.

List blocks missing

List blocks (to manipulate list variables) not yet implemented. This is mainly a problem for the converter as no mapping for the blocks exists.

repeat block with no contents generates bad output

Build a scratch project that is just:

when this sprite clicked:
repeat 10

The output from conversion is:

... snip ...
def when_this_sprite_clicked_1(self):
    for _ in range({{TIMES}}):
        {{SUBSTACK | indent(4)}}


sprite1.when_this_sprite_clicked(when_this_sprite_clicked_1)

stage.play()

The odd thing is that if you put something in the substack, then it says 10 instead of TIMES in the for loop.

So, there may be multiple issues here, actually.

Error in code generation

From Discord (User PrimeDev):

Conversion of project: https://scratch.mit.edu/projects/651198900/

Results in a file where from line 1191, the following is produced:

def when_i_start_as_a_clone_66(self):
    self.point_in_direction(180.0)
    self.go_to_x_y(self.get_variable("EnemyShipPos"), 125.0)
    self.show()
    while True:
        self.wait(0.5)
        self.start_sound("lasersmall_002")
        self.set_variable("EnemyBulletMode", "PointDownwards")
        self.set_variable("EnemyBulletX", self.x_position())
        self.set_variable("EnemyBulletY", self.y_position())
        self.create_clone_of("NO TRANSLATION: control_create_clone_of_menu")

enemy_spaceship.when_i_start_as_a_clone(when_i_start_as_a_clone_66)

def {{func}}_{{ID}}(self):
    {{NEXT | indent(4)}}

{{CURRENT_SPRITE}}.{{func}}({{func}}_{{ID}})


def when_i_start_as_a_clone_68(self):
    if (self.x_position() == 100):
        while True:
            while not (self.x_position() < 0):
                self.change_x_by(-3.0)

            while not (self.x_position() > 185):
                self.change_x_by(3.0)

    if (self.x_position() == -100):
        while True:
            while not (self.x_position() > 0):
                self.change_x_by(3.0)

            while not (self.x_position() < -185):
                self.change_x_by(-3.0)

Full export here:

message.txt

Conversion script generates: NO API method for func.opcode incorrectly.

Examples:
If the scratch block is "motion_goto", there are two choices: random, and mouse, when converter trying to convert this, it generates "NO API method for motion_goto_menu"

If the scratch block is "motion_glideto", there are two choices: random, and mouse, when converter trying to convert this, it generates
"NO API method for motion_glideto_menu"

This error message comes out here: https://github.com/pystage/pystage/blob/main/src/pystage/convert/code_writer.py#LL141C12-L141C12

Drawn backdrop svg is not shown in the correct place after conversion

I created a new backdrop by drawing a small circle around the middle of the stage area. After conversion, the circle is shown in the upper-left corner of the screen, not in the center.

In the projects.json file, in the costumes area, there is this record:

{
         "name": "backdrop2",
         "bitmapResolution": 1,
         "dataFormat": "svg",
         "assetId": "9986d9d83acb70bdcc8576b08711885c",
         "md5ext": "9986d9d83acb70bdcc8576b08711885c.svg",
         "rotationCenterX": 22.004615888596675,
         "rotationCenterY": 26.298916928788827
}

I can find no information in the project.json that says where this backdrop should be placed on the screen. Looking at the svg file itself, there are width and height fields and other stuff. Here is the beginning of the svg file:

<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="45.00462" height="51.09243" viewBox="0,0,45.00462,51.09243"><g transform="translate(-217.99538,-153.70108)"><g data-paper-data="{&quot;isPaintingLayer&quot;:true}" fill="#9966ff" fill-rule="nonzero" stroke="none" stroke-width="0.5" stroke-linecap="butt" stroke-linejoin="miter" stroke-miterlimit="10" stroke-dasharray="" stroke-dashoffset="0" style="mix-blend-mode: normal">

Perhaps the transform info in the svg says how to place the image on the screen?...

I'll do more experimenting and see if I can figure out how to determine where the svg image should be placed on the stage...

Document the use of operators

These are all operator blocks in Scratch. Operators are all available in python. They just need to be documented for people coming from scratch, but also for programming newbies.

  • +-*/
  • pick random from range (inclusive)
  • < > =
    and / or / not
    join
    letter 1 of string
    length of string
    string contains a
    mod
    round
    abs/floor/ceiling/sqrt/sin/cos/tan/asin/acos/atan/ln/log/e^/10^

A hat block with nothing attached causes bad output in the python file

Just create a scratch project with a single "when green flag clicked" block, and nothing attached to it. After conversion the result is:

from pystage.en import Sprite, Stage

stage = Stage()
stage.add_backdrop('backdrop1')
stage.create_variable('my variable')
sprite1 = stage.add_a_sprite(None)
sprite1.set_name("Sprite1")
sprite1.set_x(-54.958536902205225)
sprite1.set_y(29.050834150445024)
sprite1.go_to_back_layer()
sprite1.go_forward(1)
sprite1.point_in_direction(-75)
sprite1.add_costume('costume1', center_x=48, center_y=50)
sprite1.add_costume('costume2', center_x=46, center_y=53)
sprite1.add_sound('meow')

def {{func}}_{{ID}}(self):
    {{NEXT | indent(4) }}

{{CURRENT_SPRITE}}.{{func}}({{func}}_{{ID}})


stage.play()

The crucial part of the project.json file is this:

     "blocks": {
        "7Ba#e[,6(88C|KP2rB|9": {
          "opcode": "event_whenflagclicked",
          "next": null,
          "parent": null,
          "inputs": {},
          "fields": {},
          "shadow": false,
          "topLevel": true,
          "x": 435,
          "y": 283
        }
      },

next is null.

I'm not sure what the proper solution is... Probably the bad lines should just not be outputted.

uninitialized if block generates bad output

Create a project that jsut has:

when this sprite clicked:
if then

Output is:

... snip ...
def when_this_sprite_clicked_1(self):
    if {{CONDITION}}:
        {{SUBSTACK | indent(4)}}

Similar to issue #34

Establish system for i18n

We need full translations, not only of the API but also of all text printed to stdout so that we can give meaningful feedback where possible.

The addition and maintenance of further languages has to be as easy as possible. For the API translations, it is important that they work in editors with auto completion, so no dynamic generation of the functions, but a script that generates the api from translation files could be a good idea.

There are systems like gettext (included in Python) or modules like python-i18n, they could be worth another look, but currently I think a simple system using JSON files would be enough.

Conversion of input to move() block causes stack trace in conversion

When converting this Scratch project, https://scratch.mit.edu/projects/44316116/, the resulting json contains this movesteps block:

    "p}:lf]e~+udF{Q1K)Cg2": {
      "opcode": "motion_movesteps",
      "next": "`17EC{dJnXCZk0C/zXO~",
      "parent": "P-^9l8t(g]U4_g+/%;uV",
      "inputs": { "STEPS": [1, [4, 10]] },
      "fields": {},
      "shadow": false,
      "topLevel": false
    },

Conversion produces this error:

  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Users/vtn2/src/pystage/src/pystage/convert/sb3.py", line 449, in <module>
    project = get_intermediate(data, project_name)
  File "/Users/vtn2/src/pystage/src/pystage/convert/sb3.py", line 235, in get_intermediate
    block = get_block(b, blocks, target["isStage"])
  File "/Users/vtn2/src/pystage/src/pystage/convert/sb3.py", line 158, in get_block
    res["next"] = get_block(blocks[block["next"]], blocks, stage)
  File "/Users/vtn2/src/pystage/src/pystage/convert/sb3.py", line 156, in get_block
    res["params"][i] = get_block(blocks[value], blocks, stage)
  File "/Users/vtn2/src/pystage/src/pystage/convert/sb3.py", line 154, in get_block
    res["params"][i] = get_input_value(value, stage)
  File "/Users/vtn2/src/pystage/src/pystage/convert/sb3.py", line 104, in get_input_value
    if value.strip() == '':
AttributeError: 'int' object has no attribute 'strip'

This is because the value is 10, not "10", so you cannot strip() an integer.

When I edited this project, replacing 10 by 10 (yes, just erasing 10 and retyping it), then the resulting json is correct, putting 10 in double quotes as a string...

So, the solution may be to not trust that a value of "type" 4 (number) is represented by a string in the json, and actually test it before calling strip().

Think/say for seconds

Need to implementing the think for seconds block and say for seconds block

def looks_thinkforsecs(self, text, secs):
pass

def looks_sayforsecs(self, text, secs):
pass

Sprite - sensing: sensingtouchingobject_sprite() not working

I tried making a pong game while trying to learn pystage..

the whole code:

from pystage.core import CoreSprite, CoreStage

stage = CoreStage(name='Pong')

playerbar = stage.pystage_createsprite(None)
playerbar.motion_setx(0)
playerbar.motion_sety(-140)
playerbar.pystage_addcostume('image')

ball = stage.pystage_createsprite(None)
ball.motion_setx(0)
ball.motion_sety(0)
ball.pystage_addcostume('Untitled')

def ballmove(self):
	self.motion_setx(0)
	self.motion_sety(100)
	self.motion_turnleft(90)
	self.motion_turnleft(self.operator_random(-180,180))
	while True:
		self.motion_movesteps(5)
		if (220 < self.motion_xposition()):
			self.motion_turnleft(45)
		elif (-220 > self.motion_xposition()):
			self.motion_turnleft(45)
		elif (160 < self.motion_yposition()):
			self.motion_turnright(45)
		elif (-160 > self.motion_yposition()):
			self.control_wait(1)
			self.motion_setx(0)
			self.motion_sety(100)
			self.motion_turnleft(self.operator_random(-180,180))
		if (self.sensing_touchingobject_sprite(playerbar)):
			self.motion_sety(0)
			print("touched..")

def playerbar_work(self):
	while True:
		pass #this is a TODO which i will do later on..

ball.event_whenflagclicked(ballmove)
playerbar.event_whenflagclicked(playerbar_work)

stage.pystage_play()

I don't know how may I use the self.sensing_touchingobject_sprite(playerbar)

whenever the ball touches the playerbar, it does not go back to y(0)

and it just returns None all the time!

Resizable Window and Fullscreen

Currently, the window has a fixed size with the dimensions of the stage. It would be great to be able to resize it and also to put it in fullscreen mode with a key combination (I suggest F5 with a function to modify it as necessary, as F-keys are not usable in Scratch).

The stage should be scaled with a fixed aspect ratio. This is realized by rendering to an own surface and the provision of an access to mouse coordinates that calculate back to stage coordinates.

TypeError: rect() takes no keyword arguments

When im trying to start my program, i have an issue with pygames. Here is the error :

New costume: backdrop1 -> C:\Users\Me\AppData\Local\Programs\Python\Python38\lib\site-packages\pystage\images\zombie_idle.png
Traceback (most recent call last):
  File "c:/Users/Me/Documents/script/test/scratch_project.py", line 8, in <module>
    stage.pystage_makevariable('costume')
  File "C:\Users\Me\AppData\Local\Programs\Python\Python38\lib\site-packages\pystage\core\_variables.py", line 82, in pystage_makevariable
    monitor = Monitor(self, name)
  File "C:\Users\Me\AppData\Local\Programs\Python\Python38\lib\site-packages\pystage\core\monitors.py", line 40, in __init__
    self.update_image()
  File "C:\Users\Me\AppData\Local\Programs\Python\Python38\lib\site-packages\pystage\core\monitors.py", line 62, in update_image
    pygame.draw.rect(rect_surface, self._color, (0,0, rect_w, rect_h), border_radius=3)
TypeError: rect() takes no keyword arguments

How to Make My Scratch Project Work: Seeking Assistance with Image and Audio Addressing

Congratulations on the program initiative. pystage its a great idea!

Unfortunately, I couldn't get my Scratch program to work. My game didn't run here, and I think it's because I didn't know how to reference and address my images and audios. Can someone help me with this?

Thank you and congratulations. Below is the code converted to Python using pystage and after, and my Scratch project its: santospunk

from pystage.en import Sprite, Stage

stage = Stage()
stage.add_backdrop('hurricane')
stage.add_backdrop('canal6')
stage.add_backdrop('menu')
stage.add_backdrop('policia')
stage.add_backdrop('gonzaga')
stage.add_backdrop('gonzaga2')
stage.add_backdrop('bruno_1')
stage.create_variable('minha variável')
stage.create_variable('Quando tocar')
heric = stage.add_a_sprite(None)
heric.set_name("heric")
heric.set_x(-38)
heric.set_y(-113.07400703430176)
heric.go_to_back_layer()
heric.go_forward(6)
heric.point_in_direction(90.00848266674804)
heric.set_size_to(195.65217391304347)
heric.add_costume('char', center_x=82, center_y=276, factor=2)
heric.add_sound('aqui')
heric.add_sound('para_proteger_')
heric.add_sound('acidade_')
heric.add_sound('mas_o_que_ninguem_')
heric.add_sound('nas_primeiras_')
heric.add_sound('passou_a_ser_devastada')
heric.add_sound('que_nome_idiota')
heric.add_sound('matanza_bom_quando_faz_mal')
heric.add_sound('recording1')

def when_program_starts_1(self):
    self.switch_backdrop_to("canal6")
    self.set_size_to(40.0)
    self.say_for_seconds("Olá forasteiro", 3.0)
    for _ in range(11):
        self.wait(0.5)
        self.change_size_by(10.0)

    self.change_size_by(100.0)
    self.ask_and_wait("Qual o seu nome?")
    self.broadcast("mensagem 1")
    self.play_sound_until_done("que_nome_idiota")
    self.say_for_seconds("Que nome idiota!", 2.0)
    self.say_for_seconds("".join(["Bom... ", self.answer()]), 2.0)
    self.play_sound_until_done("aqui")
    self.switch_backdrop_to("menu")
    self.hide()
    self.play_sound_until_done("matanza_bom_quando_faz_mal")

heric.when_program_starts(when_program_starts_1)

def when_key_pressed_2(self):
    self.stop_all_sounds()
    "NO TRANSLATION: procedures_call"

heric.when_key_pressed("any", when_key_pressed_2)
ator2 = stage.add_a_sprite(None)
ator2.set_name("Ator2")
ator2.set_x(-10)
ator2.set_y(123)
ator2.go_to_back_layer()
ator2.go_forward(1)
ator2.hide()
ator2.add_costume('fantasia1', center_x=-61.107793671612114, center_y=-8.823284642443156)
ator2.add_sound('saltar')
self.when_backdrop_switches_to("MENU")
self.wait(4.0)
self.show()
self.go_to_x_y(480.0, 123.0)
self.go_to_back_layer()
self.glide_to_x_y(0.3, -10.0, 123.0)
self.wait(1.0)
self.when_backdrop_switches_to("policia")
self.hide()

def when_program_starts_3(self):
    self.hide()

ator2.when_program_starts(when_program_starts_3)
angela = stage.add_a_sprite(None)
angela.set_name("angela")
angela.set_x(176)
angela.set_y(-63)
angela.go_to_back_layer()
angela.go_forward(4)
angela.set_size_to(150)
angela.hide()
angela.add_costume('angela', center_x=141, center_y=334, factor=2)

def when_program_starts_4(self):
    self.hide()

angela.when_program_starts(when_program_starts_4)
self.when_backdrop_switches_to("MENU")
self.wait(1.0)
self.show()
self.when_backdrop_switches_to("policia")
self.hide()
image_1 = stage.add_a_sprite(None)
image_1.set_name("image-1")
image_1.set_x(139)
image_1.set_y(187)
image_1.go_to_back_layer()
image_1.go_forward(8)
image_1.set_size_to(300)
image_1.add_costume('rio', center_x=138.99999999999991, center_y=-0.19999999999984652)
self.when_backdrop_switches_to("HURRICANE")
self.wait(21.0)
self.switch_costume_to("rio")
self.show()

def when_program_starts_5(self):
    self.hide()

image_1.when_program_starts(when_program_starts_5)
bruno_menu = stage.add_a_sprite(None)
bruno_menu.set_name("bruno menu")
bruno_menu.set_x(-188)
bruno_menu.set_y(-78)
bruno_menu.go_to_back_layer()
bruno_menu.go_forward(3)
bruno_menu.set_size_to(150)
bruno_menu.hide()
bruno_menu.add_costume('bruno_menu', center_x=134, center_y=342, factor=2)

def when_program_starts_6(self):
    self.hide()

bruno_menu.when_program_starts(when_program_starts_6)
self.when_backdrop_switches_to("MENU")
self.wait(2.0)
self.show()
self.when_backdrop_switches_to("policia")
self.hide()
general = stage.add_a_sprite(None)
general.set_name("general")
general.set_x(-8)
general.set_y(-149)
general.go_to_back_layer()
general.go_forward(2)
general.set_size_to(150)
general.hide()
general.add_costume('general', center_x=122, center_y=360, factor=2)

def when_program_starts_7(self):
    self.hide()

general.when_program_starts(when_program_starts_7)
self.when_backdrop_switches_to("bruno 1")
self.wait(8.0)
self.show()
self.set_size_to(150.0)
self.when_backdrop_switches_to("HURRICANE")
self.hide()
ator1 = stage.add_a_sprite(None)
ator1.set_name("Ator1")
ator1.set_x(10)
ator1.set_y(-34.75)

stage.play()

Implement Cloning

As requested on Discord, we should implement support for clones. As this is probably not trivial, we use this issue for discussions around the implementation.

Implement/document custom blocks

Some thoughts: My Blocks (custom blocks)

a custom block is simply a generator or a function (we need to distinguish here!)
generators (long running blocks that need yields) are invoked with yield from
functions as usual (they block the thread).
Scratch does not support custom reporters, actually, unlike Snap.
Reporters would be functions, as only this way we can work with the return value

Error says can;t find file

I typed:
python -m pystage.convert.sb3 casg.sb3 -l en -d Downloads
and I get an error "FileNotFoundError: [Errno 2] No such file or directory: 'casg'" I need help because I don't know how to fix that erroe I tried everything.

key_pressed does not get correctly converted

From Discord:

I have if keypressed "a" in my scratch block and it is converted to

if self.key_pressed("NO TRANSLATION: sensing_keyoptions"):
If I manually change "NO TRANSLATION: sensing_keyoptions" to "a", then it works.

I have a porblem with export.

I have an error:
Traceback (most recent call last):
File "", line 189, in run_module_as_main
File "", line 112, in get_module_details
File "C:\Users\tymon\VNEV\Lib\site-packages\pystage\convert_init
.py", line 1, in
from .code_writer import CodeWriter
File "C:\Users\tymon\VNEV\Lib\site-packages\pystage\convert\code_writer.py", line 11, in
from pystage.core.sprite import CoreSprite
File "C:\Users\tymon\VNEV\Lib\site-packages\pystage\core_init
.py", line 1, in
from .sprite import CoreSprite
File "C:\Users\tymon\VNEV\Lib\site-packages\pystage\core\sprite.py", line 2, in
import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'
Please for help.
Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.