11 November 2013 | |
![]() |
|
www.luminous-arts.com
portfolio
George Lambrakis
3D lead
Luminous Arts
New York City,
USA
|
![]() Hi all,
I'm trying to pass a selection from multiple functions to a single function and have that function manip the forward vars. But it's not working.. here is pseudocode:
So this doesn't make sense to me. isn't the bodyMesh passed to the function as an argument? shouldn't the objs object point back to the object passed into the function? Why is it undefined? I must be missing something, a scoping issue, or a deep/shallow reference issue, etc.. Any light that can be shed on the subject would be greatly appreciated! -Thanks! __________________
http://www.luminous-arts.com |
11 November 2013 | |
![]() |
|
Expert
portfolio
Kostadin Kotev
Blagoevgrad,
Bulgaria
|
__________________
|
11 November 2013 | |
![]() |
|
www.luminous-arts.com
portfolio
George Lambrakis
3D lead
Luminous Arts
New York City,
USA
|
[edit]
Thanks miauu.. looks like I'm calling the functions incorrectly.. __________________
http://www.luminous-arts.com Last edited by Yorgo12345 : 11 November 2013 at 08:38 PM. |
11 November 2013 | |
![]() |
|
www.luminous-arts.com
portfolio
George Lambrakis
3D lead
Luminous Arts
New York City,
USA
|
ok, I was able to solve my issue by using a return function instead, but I still couldn't get the forward reference to work.
Even though I don't need it anymore, I'd still like to know what I was doing wrong. Miauu, the example you wrote didn't seem to solve it. I'm just curious...what aren't I understanding about this? __________________
http://www.luminous-arts.com |
11 November 2013 | |
![]() |
|
Expert
portfolio
Kostadin Kotev
Blagoevgrad,
Bulgaria
|
You calling the main function incorectly.
bodyMesh is undefined The main fn:
Then you have:
This means: 1- you call the function and pass bodyMesh, so
objs gets new values - all the picked objects. 2- the fn returns the objs, because it is the last parameter in it, but... you did not collect this value. If you have:
Then the bodyMesh will holds the picked objects, that fn returns(the objs variable). Having only
will execute the function, but since all variables in the fn is local, they are not visible outside of it, so you will not have the selected objects outside of the fn. One way to get the objs value outside of the fn is to use:
There is no need to pass bodyMesh to the fn. Other way is to use this:
Now, bodyMesh is defined outside of the fn as local variable and when the fn is executed the bodyMesh will change its values. But if you have:
After the execution of the fn, the bodyMesh still will be undefined, because in the fn bodyes you have declared bodyMesh as local, to the function, variable. You can check maxscript help file for "by reference". I am sure that someone can explain this better than me. ![]() __________________
Last edited by miauu : 11 November 2013 at 09:39 PM. |
11 November 2013 | |
![]() |
|
www.luminous-arts.com
portfolio
George Lambrakis
3D lead
Luminous Arts
New York City,
USA
|
Quote:
One way to get the objs value outside of the fn is to use:
Code: bodyMesh = grabObjs() Yes, This is exactly what I ended up doing. It worked. I guess I am just used to other languages where the scope seems to behave differently. I have freequently forward declared variables, and paseed them into funtions for manipulation or assignment.. If that's just not the way maxscript works, that's fine. ..Also, I didn't know that maxscript functions automatically return the last parameter! Werid! ..but cool. - I'll get used to it ![]() thanks again Miauu! __________________
http://www.luminous-arts.com |
11 November 2013 | |
![]() |
|
Scout
Christoph Bülter
Germany
|
By default maxscript passes parameters to functions by value, not by reference. So the original variable is not changed if you do not assign the function result to it. You can however pass by reference using "&". You have to put it in front of any paramater that you want to pass by reference in the function definition and whenever calling the function, so the actual variable is changed. Like so:
__________________
www.cbuelter.de |
11 November 2013 | |
![]() |
|
Expert
|
Thread automatically closed
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities Note that as CGTalk Members, you agree to the terms and conditions of using this website. |
Thread Closed share thread |
«
Previous Thread
|
Next Thread
»
|
|
|