can't figure out why an error is an error - passing a parameter to pos property

392 views
Skip to first unread message

Erik the Anarchitect

unread,
Aug 6, 2016, 10:20:15 PM8/6/16
to Glowscript Users
So what I am doing is something where I have pictures of randomly-generated imaginary buildings, and elements of them can be randomly positioned.

So for instance for a box that is one wing of a sprawling mansionlike building I tried something like

def leftwing(whereabouts, direction, storeys):
    box( pos = whereabouts, axis=direction, L=6, H = storeys, W=3)

but I get an error "pos must be a vector"

well, the value I intend to pass to it IS a vector, (the variable "whereabouts" only HAS vector values in my program)
and similarly with the value named "direction"

but an interpreter might not have seen that explicitly as it is reading the declaration.

How do I tell it explicitly that "whereabouts" is a vector value?

Bruce Sherwood

unread,
Aug 6, 2016, 10:23:16 PM8/6/16
to Glowscript Users
Please provide as simple a test case as possible that illustates the problem. The following program works as expected:

GlowScript 2.1 VPython
def f(v):
    print(2*v) # prints <2,4,6> correctly
    
a = vec(1,2,3)
f(a)

Bruce Sherwood

unread,
Aug 6, 2016, 10:32:36 PM8/6/16
to Glowscript Users
And this works, too:

GlowScript 2.1 VPython
def f(v):
    box(pos=v)
    
a = vec(2,0,0)
f(a)

Jethomas5

unread,
Aug 7, 2016, 5:15:35 PM8/7/16
to Glowscript Users
Maybe your problem is that the box example has things like "length = L" and you did "L=6" instead of "length=6".
 

Bruce Sherwood

unread,
Aug 7, 2016, 5:43:47 PM8/7/16
to Glowscript Users
No, setting L=6 in a box constructor wouldn't give an error about pos not being a vector, though as you say it won't affect the length of the box. Saying L=6 means that this box object has a property L with value 6,  in addition to its VPython attributes ( pos, length, color, etc.):

GlowScript 2.1 VPython
def f(v):
    b = box(pos=v, L=6)
    print(b.pos, b.L)       # displays < 2, 0, 0 > 6
    
a = vec(2,0,0)
f(a)

Erik the Anarchitect

unread,
Aug 14, 2016, 9:12:47 PM8/14/16
to Glowscript Users
Thank you for paying attention to this. Glowscript was doing what it was supposed to do. I was just confused about the syntax.


On Saturday, August 6, 2016 at 10:20:15 PM UTC-4, Erik the Anarchitect wrote:
Reply all
Reply to author
Forward
0 new messages