Grasshopper

algorithmic modeling for Rhino

Why "vSpeed(j).Z = -vSpeed(j).Z" ---> Error: Expression is a value and therefore cannot be the target of an assignment.

I don't understand why this is not allowed :S

This is the general situation:

Dim vSpeed As New List (Of Vector3d)

For statement...

vSpeed(j).Z = -vSpeed(j).Z

Next...

Error: Expression is a value and therefore cannot be the target of an assignment. 

I've solved it with this: 

Dim vZ As Vector3d

Dim vSpeed As New List (Of Vector3d)

For statement...

dZ = vSpeed(j)
dZ.Z = -dZ.Z
vSpeed(j) = dZ

Next

 

Anyone knows why this happens?

Views: 393

Replies to This Discussion

It happens because Vector3d is a Value Type ('Structure' in VB).

When you get a structure out of a list using vSpeed(i) you get a copy of the actual vector stored inside the list. When you then access the Z of this vector, you are only modifying the copy. Since this copy is not stored anywhere the compiler sees that you are performing a meaningless operation and thus warns you about it.

Your solution of getting the vector, modifying it, then putting it back is the correct approach.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Hey!, thanks for the reply David. I always like to understand things from the foundations :)

What a turn around for something really simple...¬.¬

Best Regards. 

I believe if you use an array instead of a list (meaning you have to know how many items you have in advance) you won't have this problem :) 

Mmmm...changing to arrays for some task then. 

Thanks!

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service