Skip to content

Need to create mutiple instances of scripts and output elements on the same page #39

@cyust

Description

@cyust

Thank you for working on this project! I am interested in using it in an educational setting. After some experimentation, I believe there is at least one architectural issue that would block us from using it in a production environment. Primarily, a typical "lesson" web page will need to display multiple, independent examples on the same page.

If I understand the current setup correctly, turtle-pyscript is hard-coded to display output in a

with fixed ids, e.g.:

    <div id="tps-game-area">
        <div id="tps-game-box"> </div>
    </div>

A <script> element containing code will then automatically interact with those well-known divs.

What we'd need is the ability to add multiple <script> elements and output

elements on the same page, with each script independently interacting with its own output div. Perhaps something like this...

    <div id="tps-game-area1">
        <div id="tps-game-box1"> </div>
    </div>
    <script type="py" something="... some way to target this script to tps-game-area1 for I/O...">

code for instance 1...

    </script>

    <div id="tps-game-area2">
        <div id="tps-game-box2"> </div>
    </div>
    <script type="py" something="... some way to target this script to tps-game-area2 for I/O...">

code for instance 2...

    </script>

...or even better, perhaps convert from id to class, then have each script placed within a parent

and automatically work with that
, e.g.:

    <div class="tps-game-area">
        <div class="tps-game-box"> </div>
        <script type="py">

code for instance 1...automatically interacts with the parent tps-game-area

        </script>
    </div>

    <div class="tps-game-area">
        <div class="tps-game-box"> </div>
        <script type="py">

code for instance 2...automatically interacts with the parent tps-game-area

        </script>
    </div>

In our experimentation, copying multiple <script> elements within the same page meant that each script element tried to use the same

with the unique tps-game-area id. We also received errors that indicated multiple scripts running on the same page would interfere with each other (e.g. errors from screen.register_shape() running twice).

Possibly, there are already workarounds we didn't catch for these issues - would love to see a sample HTML page demonstrating multiple instances if available :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions