A weird error message !

41 views
Skip to first unread message

陳冠榮

unread,
Oct 30, 2021, 5:52:27 AM10/30/21
to Glowscript Users
I'm studying a program written by Rob Salgado and find some weird situation as followed.

Code A generates a message of '[object Promise]':
=========================================
GlowScript 3.1 VPython
showAmpere = 1

scene = canvas(width=200, height=100, title='EM Wave v3.00 (Rob Salgado)')
box()
scene.caption = """TEST
(TEST)
TEST"""

def reverse(t): return (t+1)%2
print(showAmpere)
print(reverse(showAmpere))

未命名.jpg

Code B generates the result supposed to be.
====================================
GlowScript 3.1 VPython
showAmpere = 1

scene = canvas(width=200, height=100, title='EM Wave v3.00 (Rob Salgado)')
box()
scene.caption = """TEST
TEST)
TEST"""

def reverse(t): return (t+1)%2
print(showAmpere)
print(reverse(showAmpere))
未命名.jpg

The only difference between Code A and Code B is the left parenthesis '(' in Code A. What happened? Do I miss something? Do I have a wrong syntax?

Thanks 

CKJ

Bruce Sherwood

unread,
Oct 30, 2021, 1:06:58 PM10/30/21
to Glowscript Users
That is indeed VERY strange, that the additional left parenthesis in scene.caption should confuse the transpiling from Python to JavaScript. If you choose "Share or export this program" you'll see that in both cases the JavaScript code correctly has "aync " prepended to "function reverse(t), but in the in the final print statement there is a missing "await " when there is that additional left parens in scene.caption. Thanks very much for reporting this. At the moment I find this behavior utterly baffling.

Bruce

陳冠榮

unread,
Oct 30, 2021, 9:00:54 PM10/30/21
to Glowscript Users
In fact, the original codes (https://trinket.io/glowscript/216f415a46) of  Rob Salgado don't contain the reverse() function, I added it.  Rob Salgado did the same thing by the following code:

GlowScript 3.1 VPython
showAmpere = 1

scene = canvas(width=200, height=100, title='EM Wave v3.00 (Rob Salgado)')
box()
scene.caption = """TEST
(TEST)
TEST"""

print(showAmpere)
showAmpere += 1;   showAmpere %= 2
print(showAmpere)

'''
def reverse(t): return (t+1)%2
print(showAmpere)
print(reverse(showAmpere))
'''

And it is normal, nothing weird happens. So, I wonder whether the error message was triggered by both the reverse() function and the parenthesis.

CKJ

未命名.jpg
Bruce Sherwood 在 2021年10月31日 星期日上午1:06:58 [UTC+8] 的信中寫道:

Bruce Sherwood

unread,
Nov 8, 2021, 2:47:10 PM11/8/21
to Glowscript Users
This bug has now been fixed in version 3.2.

Bruce

Reply all
Reply to author
Forward
0 new messages