wrangle newbie

   2011   3   0
User Avatar
Member
37 posts
Joined: Aug. 2012
Offline
going through wrangle introduction tutorial and i'm new to vex/wrangle language.
i'm doing a very simple thing, a grid with random y value.

when i set “rand_y” variable it works fine.

v@rand_y = set(0, random(@ptnum), 0);
@P += @rand_y;


but when i wrote down everything in a line i got an error;

@P += {0, random(@ptnum), 0};

why is that?

hb
Edited by garin2 - June 15, 2016 17:20:32

Attachments:
Screen Shot 2016-06-15 at 2.09.14 PM.png (574.3 KB)

User Avatar
Member
605 posts
Joined: July 2013
Offline
You cannot create vectors with {} brackets.

Vectors can only be created via ‘set’ method.

If your first example, the ‘set’ method is called and vector @rand_y is created which is then assigned to @P.

In your second example, you are trying to assign an undefined vector to @P.
Houdini Indie
Karma/Redshift 3D
User Avatar
Member
37 posts
Joined: Aug. 2012
Offline
so it seems like undefined value doesn't work with {}.

because even vector statement, @P += {0,2,0}; was working but not @P += {0,random(3),0};.
thanks,

hb
User Avatar
Member
1742 posts
Joined: May 2006
Online
There's probably a better coder term for it, but I think of it more that {} only supports static values. Ie, a number. If you're constructing a vector by calling functions, or calling the result of other point attributes or vectors, you need to use set().

An alternative way is to set the components individually, which can be easier to read in some circumstances.

v@myvector;

@myvector.x = rand(@ptnum);
@myvector.y = 2;

@P += @myvector;

http://www.tokeru.com/cgwiki [www.tokeru.com]
https://www.patreon.com/mattestela [www.patreon.com]
  • Quick Links