Major improvement

44 views
Skip to first unread message

Bruce Sherwood

unread,
Sep 7, 2017, 12:24:08 PM9/7/17
to Glowscript Users
The following program gave an error until today but now works as expected -- that is, "13" is printed, then the program waits for a click, then "23" is printed, followed by "done".

box()

def f(x,y):
    print(x)
    scene.pause()
    print(y)
    
f(13,23)
print('done')

You can even put such things as pause and waitfor inside the methods of a Python class. The only limitation is that GlowScript will get confused if you have an ordinary function containing a pause with the same name as a class method containing a pause.

If you write your program in JavaScript or RapydScript, the use of the "wait" keyword is no longer necessary (it's optional, so existing programs that use "wait" will continue to work).

Bruce

P.S. I'm deeply chagrined that it took several years to see how to do this.....

Bruce Sherwood

unread,
Sep 7, 2017, 4:54:51 PM9/7/17
to Glowscript Users
Correction: Thanks to a suggestion from Ruth Chabay, GlowScript is no longer confused if you have an ordinary function containing a pause with the same name as a class method containing a pause.

The only remaining confusion I know of is if you have two different classes, each with a method of the same name, but one method contains a pause or similar statement and the other method doesn't.

Bruce

Bruce Sherwood

unread,
Sep 7, 2017, 9:56:10 PM9/7/17
to Glowscript Users
Actually, after a little bit more work, it's now the case that you can even have two classes with methods that have the same names, and whether or not neither or one or two of these methods contain a pause or similar statement, it all works. This magic works because JavaScript functions tolerate being sent more arguments than expected, the extra ones being ignored.

So now I don't know (yet) of a case that will fail.

Joe Heafner

unread,
Sep 8, 2017, 12:55:11 PM9/8/17
to GlowScript Users

> On Sep 7, 2017, at 12:24, Bruce Sherwood <bruce.s...@gmail.com> wrote:
>
> The following program gave an error until today but now works as expected -- that is, "13" is printed, then the program waits for a click, then "23" is printed, followed by "done".
>
> box()
>
> def f(x,y):
> print(x)
> scene.pause()
> print(y)
>
> f(13,23)
> print('done')
>
> You can even put such things as pause and waitfor inside the methods of a Python class. The only limitation is that GlowScript will get confused if you have an ordinary function containing a pause with the same name as a class method containing a pause.

AHA! I think this means some of my older stuff written in Classic VPython will now work as intended in GlowScript (e.g. clicking inside a function to place an electric field arrow).


Joe Heafner
Sent from one of my Macs



Bruce Sherwood

unread,
Sep 8, 2017, 2:09:58 PM9/8/17
to Glowscript Users
It is a high priority to make GlowScript VPython and VPython 7 as similar as possible, except for the unavoidable constraint that GlowScript VPython can't import from the big world of Python modules. With the ability to put statements such as pause in a subroutine a serious difference between the two flavors of VPython has been removed.

Bruce


Reply all
Reply to author
Forward
0 new messages