hedyorg / hedy

Hedy is a gradual programming language to teach children programming. Gradual languages use different language levels, where each level adds new concepts and syntactic complexity. At the end of the Hedy level sequence, kids master a subset of syntactically valid Python.
https://www.hedy.org
European Union Public License 1.2
1.29k stars 284 forks source link

🪲 For-list command stops when placed in an if_pressed statement #5681

Open boryanagoncharenko opened 1 month ago

boryanagoncharenko commented 1 month ago

Describe the bug In level 10, the following code should output all elements of the list if the key x is pressed. However, the for loop outputs the first element of the array and then the program stops:

lijstje is kip, haan, kuiken
if x is pressed
    for dier in lijstje
        print dier
else
    print 'onbekend dier'

Add a screenshot (optional)

Screenshot 2024-07-30 at 13 13 35
boryanagoncharenko commented 1 month ago

The issue seems to be that Skulpt stops the program when a time.sleep() is encountered (and there is one added at the end of the for-loop body). This seems to have been an issue before https://github.com/skulpt/skulpt/issues/764 but it should have been already addressed. Not sure if the issue persists in our fork.

We could:

Felienne commented 1 week ago

The issue seems to be that Skulpt stops the program when a time.sleep() is encountered (and there is one added at the end of the for-loop body). This seems to have been an issue before skulpt/skulpt#764 but it should have been already addressed. Not sure if the issue persists in our fork.

We could:

  • Try syncing with the latest version of Skulpt and/or attempting to fix the matter there.

I am ok with trying that but we should totally check with @jpelay whether/how that would impact us since we did a lot of work on top of Skulpt with the debugger.

  • Just remove all time.sleep statements from the body, even though that might lead to some confusion in the output.

Do you mean only in the if_pressed or in general? It is potentially a bit confusing but if it solves this problem, I am ok with it (how often, in practice are kids going to put a loop within an if statement) But if you mean in general, that would be a no for me because the small wait is very helpful!

boryanagoncharenko commented 1 week ago

I am ok with trying that but we should totally check with @jpelay whether/how that would impact us since we did a lot of work on top of Skulpt with the debugger.

Actually, I just checked that syncing the fork would not resolve the issue. The problem still exists in Skulpt and can be reproduced with the following programs:

import turtle

t = turtle.Turtle()

for c in ['red', 'green', 'yellow', 'blue']:
    t.color(c)
    t.forward(75)
    t.left(90)
    time.sleep(1)

and

step = 1
while step < 4:
    step = step + 1
    print('test')
    time.sleep(1)

Do you mean only in the if_pressed or in general? It is potentially a bit confusing but if it solves this problem, I am ok with it (how often, in practice are kids going to put a loop within an if statement) But if you mean in general, that would be a no for me because the small wait is very helpful!

Yes, I meant removing the time.sleep only for commands placed in an if-pressed statement. Ideally, I'd find a way to keep the delay because it is handy, but I agree this might be an overkill for now.

jpelay commented 1 week ago

Actually, I just checked that syncing the fork would not resolve the issue. The problem still exists in Skulpt and can be reproduced with the following programs:

Yeah, that's what I was going to say. Our version of Skulpts dates late 2023, and this issue is from 2018.

Felienne commented 1 week ago

Yes, I meant removing the time.sleep only for commands placed in an if-pressed statement

I am ok with that!