Oddball behavior

21 views
Skip to first unread message

dbor...@willamette.edu

unread,
Nov 8, 2022, 7:30:08 PM11/8/22
to Glowscript Users
Hey Bruce!

Ran into a weird bug (or feature?) today. Consider the following code:
-----------------------------------------------------
Web Vpython 3.2

cart2 =box(pos=vector (-0.2,0,0), length=0.2, height=0,1, width=0.1, color=color.blue, mass = 3)
ball = sphere(pos=vector(-3,0,0), radius = 0.5, color=color.red)
print(cart2.mass)
-------------------------------------------------------

There's a typo where the student put a comma instead of decimal place when defining the height. The result is (I think) a fully default box that ignores all the other attributes including mass, but no error is thrown and the next line defining the ball works just fine. This happens regardless of whether one sets "height = 0,1" or "height = 50,2".

One can also get a different but also weird behavior if one tries 

-----------------------------------------------------
Web Vpython 3.2

cart2 =box(pos=vector (-0.2,0,0), size=vec(0.2,1,1,0.1), color=color.blue, m = 3)
ball = sphere(pos=vector(-3,0,0), radius = 0.5, color=color.red)
print(cart2.mass)
-------------------------------------------------------

Here the typo is in the second component of size, where 1.1 becomes 1,1. In this case a box with length 0.2, height 1, and width 1 is created. No idea what happens with the 3rd (now 4th component) of the vector. I guess it just doesn't get processed. I imagine that the vector class being able to accept more than 3 components makes sense, so the behavior here makes more sense, although maybe the 3D objects should reject vector that aren't 3D unless there is a use case that I am not thinking about (maybe for relativistic 4-vectors?).

Anyway, I just figured I'd let you know.

Cheers,

Daniel

Bruce Sherwood

unread,
Nov 9, 2022, 1:06:55 PM11/9/22
to Glowscript Users
Interesting, but there may not be anything I can do to improve the first case, "1" looks like it might be a legitimate parameter being sent to a function (box). In the second case, it's conceivable that I could detect vec(1,2,3,4) as an error. 

Bruce

Bruce Sherwood

unread,
Nov 9, 2022, 1:18:08 PM11/9/22
to Glowscript Users
I see that with installed Python the first case does give an error, "positional argument follows keyword argument", so I should report that error to the RapydScript-ng developer. The second case also gives an error with installed Python; I should be able to check for that.

Bruce

Reply all
Reply to author
Forward
0 new messages