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.34k stars 292 forks source link

🪲 If key pressed could be assigned a multi-letter string #5727

Closed boryanagoncharenko closed 20 hours ago

boryanagoncharenko commented 3 months ago

Describe the bug The if-pressed command allows variables on the left-hand-side. A variable could be assigned any value including a multi-char value. At the same time the if-pressed logic only allows a single key to be pressed and has no support for combinations of key presses. So, in this case there is no way for the if-pressed statement to be correct.

Paste the Hedy code & level In level 9, execute the following snippet. Note that whatever you type, the output great will never get printed.

x is asdf
if x is pressed
    print 'great'
else
    print 'not great'

Possible solutions

  1. We could just take the first letter of the multi-letter value. For example if the x = 20 + 1, the the if-pressed would succeed on pressing the key 2. This solution could be confusing though.
  2. We could issue a warning at runtime (not sure if we have the mechanism for that?) that lets the user know that it is a multi-letter string so it will not work.
jpelay commented 3 months ago

I think option 2 is better, after all skulpt lives in JavScript and I think we could show the alert during the execution of the program, and let it continue, or finish it like we do when someone presses the stopit button.