|
-
Jul 22nd, 2020, 03:09 PM
#1
Thread Starter
Lively Member
Trouble with assigning the result of a function to a property
Hi, my issue is that I can't seem to be able to assign a function's return value to an instance of a Class of same type:
vb.net Code:
Dim MTranslate_Z As Matrix3D = Matrix3D.Create_Scale(2, 2, 2)
For Each Vertex As PVector In PTriangle.Vertices
Dim unused As PVector = MTranslate_Z.MultiplyVector(Vertex)
Vertex = unused
Next
More info on the above:
-PTriangle.Vertices is a property that returns an array of PVector objects.
-The "MultiplyVector" Function of the matrix returns a PVector object.
I want to assign the object returned by the function to each object looped trough in the array but it tells me "Unnecessary assignment of a value to Vertex"
I thought of making it a sub and directly change the PVector but I rather keep it as a function, how should I proceed ?
Is it in the PVector Class that I need to add something to allow this ?
Thanks in advance for the help !
-
Jul 22nd, 2020, 03:43 PM
#2
Re: Trouble with assigning the result of a function to a property
Vertex is a reference to an object in PTriangle.Vertices.
If you change Vertex to point to your local instance "unused", that will have no effect on the object in PTriangle.Vertices.
You want to change the object that Vertex is referencing, which means you want to change the object in PTriangle.Vertices.
You probably don't want a For Each here, but need to iterate the Vertices collection so you can assign the "unused" reference to the indexed Vertices reference.
I'm not the expert though, so would have to research the best syntax for this.
"Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930
-
Jul 22nd, 2020, 04:37 PM
#3
Re: Trouble with assigning the result of a function to a property
Yeahh, you don't want a for each here.... you want a good ol' fashioned For loop... reference the items in the array through their index and assign the result frmo the function to the indexed element directly:
Code:
For x as integer = 0 to PTriangles.Vertices.Length-1
Dim Vertex As PVector = PTriangles.Vertices(x)
PTriangles.Vertices(x) = MTranslate_Z.MultiplyVector(Vertex)
Next
-tg
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|