Weird GlowScript bug on Trinket

70 views
Skip to first unread message

Brett Taylor

unread,
Feb 18, 2022, 10:34:55 AM2/18/22
to Glowscript Users
One of my students unwittingly discovered a bug with GlowScript 3.1 on Trinket.io.  This bug does not seem to happen in my testing on glowscript.org with 3.0, 3.1, or 3.2.

The bug was discovered while using  the built-in abs  to make sure the returned value from the function.  It appears the problem is how variables are being returned from the function (and not abs).  Example code below showing the bug:

GlowScript 3.1 VPython
def f(x):
  f = x + 0.0001
  return(f)

v1 = 2432.0
v2 = -1432.0
v3 = -0.495

print("abs(v1) = ", abs(v1))
print("abs(v2) = ", abs(v2))
print("abs(v3) = ", abs(v3))

print("abs(v1) = ", abs(f(v1)))
print("abs(v2) = ", abs(f(v2)))
print("abs(v3) = ", abs(f(v3)))

The bottom set of code when returned from a function gives NaN as results.  If I change to 3.0, then it works fine (GlowScript 3.2 is not available yet on Trinket). 

This seems to be something tied to returning the value of the function since you can do print("abs(v1) = ", abs(f(v1)))
print("abs(v2) = ", abs(f(v2)))
print("abs(v3) = ", int(f(v3)))

which gives an error and won't run:

Invalid literal for int with base 10: [object Promise]

Bruce Sherwood

unread,
Feb 18, 2022, 11:18:14 AM2/18/22
to Glowscript Users
Evidently trinket.io never kept up with developments on version 3.1 (and as you say 3.2 isn't there). There was a very long period of work on 3.1 to move from the use of the Streamline library, which made possible infinite loops, to use what was at the time a new capability in JavaScript, the use of "await" and "async". If you run the program at webvpython.org in version 3.1 or 3.2 and click "Share or export this program" you'll see "await" prepended to calls to function f(x). Apparently Trinket's version of 3.1 didn't pick up the final version of 3.1.

I suggest that you lobby Trinket to offer 3.2.

Bruce

Brett Taylor

unread,
Feb 21, 2022, 1:03:12 PM2/21/22
to Glowscript Users
Thanks Bruce - I assumed it was some kind of internal to Trinket issue.  I'll see what they have to say.

Brett
Reply all
Reply to author
Forward
0 new messages