PencilCode / pencilcode

An online IDE for kids: pencilcode.net.
http://dev.pencilcode.net/
MIT License
167 stars 100 forks source link

console.log and alert executions are happening at the beginning of the program execution #197

Closed dinukadesilva closed 9 years ago

dinukadesilva commented 9 years ago

When there are console.log and alert in the program, all of them are executed at the beginning of the program execution. This seems like an issue in pencil-tracer

dinukadesilva commented 9 years ago

Here is an example http://dinuka.pencilcode.net/edit/console_alert_bug

davidbau commented 9 years ago

This issue is unrelated to pencil tracer.

It is a fundamental issue with the way the turtle library works. Since javascript is a nonblocking environment, you cannot write code where fd(100) takes one second and "blocks" the program until the next line of code. Instead, you must queue animations to be executed later.

This is how jQuery and all animation libraries in Javascript work. The result is that all queued actions run slowly and in the future, but unqueued actions such as console.log occur right away.

I can imagine a total resdeign that takes a different approach to this problem, but it's not a small bug.

davidbau commented 8 years ago

This is not a bug, but a design choice. See:

https://groups.google.com/forum/#!searchin/pencilcode/animation$20order/pencilcode/idx8JB6Oxls/37jqJhzGDS4J as well as http://ref.pencilcode.net/turtle/speed.html

On Sun, Sep 6, 2015 at 6:14 AM, Dinuka2013513 notifications@github.com wrote:

Here is an example http://dinuka.pencilcode.net/edit/console_alert_bug

— Reply to this email directly or view it on GitHub https://github.com/PencilCode/pencilcode/issues/197#issuecomment-138062284 .

xinan commented 8 years ago

Is there any way to work around it easily?

davidbau commented 8 years ago

Use "await turtle.done defer()" in front of the parts of the code that you want to block to wait until after the turtle is finished moving.

On Tue, Nov 10, 2015 at 11:26 AM, Liu Xinan notifications@github.com wrote:

Is there any way to work around it easily?

— Reply to this email directly or view it on GitHub https://github.com/PencilCode/pencilcode/issues/197#issuecomment-155474308 .