rate query

40 views
Skip to first unread message

kblack...@googlemail.com

unread,
Mar 6, 2017, 10:21:45 AM3/6/17
to Glowscript Users
Hi,

Sorry to pester. When I run the following example I am getting the error message "SyntaxError: Expected '(' null:

GlowScript 2.4 VPython

a = 2
try:
   
    print(int(a))
   
except ValueError:
   
    print("Error")

while True:
    rate(1)
    print("test")
 
Do you know why this wouldn't work?

Thanks again  

kblack...@googlemail.com

unread,
Mar 6, 2017, 10:36:28 AM3/6/17
to Glowscript Users
I have checked and this simpler example doesn't work.

while True:
    rate(1)
    
    try:
   
        print("test")
   
    except ValueError:
   
        print("error")

It seems to be when there is a while loop.

Bruce Sherwood

unread,
Mar 6, 2017, 11:08:03 AM3/6/17
to Glowscript Users
It is odd that when I try your first program I get  "SyntaxError: Unxpected token '(' , not  "SyntaxError: Expected '(' ,

Following up on your second program, I deleted the while loop from your first program and saw that the try/except machinery worked properly. Clearly there is some interaction between try/except and the Streamline machinery that permits the use of infinite while loops. I don't know what the solution is, or whether a solution is even possible.

kblack...@googlemail.com

unread,
Mar 6, 2017, 12:23:00 PM3/6/17
to glowscri...@googlegroups.com
Do you know of any way to check if a value is an integer/float that doesn't rely on try/except that works within glowscript with an infinite loop? Thanks again :)


On Monday, 6 March 2017 15:21:45 UTC, kblack...@googlemail.com wrote:

Bruce Sherwood

unread,
Mar 6, 2017, 1:05:15 PM3/6/17
to Glowscript Users
The following works in either GlowScript VPython or Jupyter VPython:

if type(x) == type(1) or type(x) == type(1.2):
     print('number')
else:
    print('not a number')

In GlowScript, the RapydScript-NG transpiler converts Python to JavaScript, and in JavaScript all numbers are in fact floats. In Jupyter, using true Python, ints and floats are two different types.

kblack...@googlemail.com

unread,
Mar 8, 2017, 9:07:24 AM3/8/17
to Glowscript Users
The following work for me. Sorry, I didn't do a good job of explaining. It was the input from the text boxes. if not isNaN(parseFloat($("#mass").val(),10))
Thank you very much for your help.

On Monday, 6 March 2017 15:21:45 UTC, kblack...@googlemail.com wrote:

karlbl...@gmail.com

unread,
Oct 20, 2017, 12:15:03 PM10/20/17
to Glowscript Users
Hi Bruce,

I have a new gmail account and have forgotten what my old one was. It was me who asked this question. I did some work that I would like to get access to. Is it still possible?

Kind regards

Bruce Sherwood

unread,
Oct 20, 2017, 2:33:37 PM10/20/17
to Glowscript Users
I think it was kblacker2520.

Bruce

--

---
You received this message because you are subscribed to the Google Groups "Glowscript Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to glowscript-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages