PDA

View Full Version : Is there a way to return more than 1 var from proc?


instruct9r
11-25-2006, 10:40 AM
Ok I have little problem here and i was wondering.. is there a way to return more than one variable from a procedure?

Let's say we have procedure (that is called from button) that is storing the current Translates, rotates and scale in a 3 different vector[] variables.. What i want those 3 vectors to be visible in other procedure (without calling the first procedure again)... So can i return 3 different vectors??

Other question is.. how i can make one procedure to be executet only once, when showing the UI..

The reason for this is i want a button that can store translates, rotates and scales for all selected objects in a vector[] and those vector[] to be visible in other procedure....

10x

cpan
11-25-2006, 11:36 AM
you can make your procedure have 3+ vector arguments (that will get returned by reference) like this:


proc myProc(vector $transl, vector $rotate, vector $scale)
{
...
... code that calculates $transl, $rotate etc
...
...
}

proc myCallingProc()
{
// cause you declared the vars before the proc, these will get referenced by myProc

vector $tr, $rot, $sc;
myProc($tr,$rot,$sc);

print $tr;
print $rot;
print $sc;
}


hope this is what you asked :D

salut,
calin

instruct9r
11-25-2006, 12:38 PM
Thanks but i may not explaining this good...

ok let's say it this way
Is there a way to call a procedure only once and after that only to have access to the values that it returns (from another procedure) without calling it everytime.....

grantimus
11-25-2006, 08:40 PM
If you want one single procedure to collect these values and you only want to call the procedure one you have a couple of different options.

You could have that procedure store your position, rotation, and scale in 3 different global variables. I wouldn't go for this because in my opinion too many global variables gets messy. That is just my personal opinion though. If it works for you, go for it.

What I would do is have the procedure return a float array where this first three positions in the array are the objects position, the second three rotation, and the last three scale. So if you had an object with the position of 3,4,9, a rotation of 23,89,45 and a scale of 1,1,1. The variable would read 3 4 9 23 90 45 1 1 1.

Or, if you are comfortable working with them, it wouldn't be hard to store the object's transformation matrix.

instruct9r
11-25-2006, 08:50 PM
Yep.. that i was thinking... to store them in a matrix because this way it may be like this

variable[0][3] = translates
variable[1][3] = rotates
variable[2][3] = scales

and this should work fine... BECAUSE i'm planing to have more than one object selected and in the way you explained with the array:
first 3 - translates
second 3 - rotates
third 3 - scales...

that's cool.. but it will be hard to get them back when i need them... i will have to do some weird loop :eek:

anyway i fix that thanks for the help

sunit
11-26-2006, 05:44 AM
proc myProc(vector $transl, vector $rotate, vector $scale)
{
...
... code that calculates $transl, $rotate etc
...
...
}

proc myCallingProc()
{
// cause you declared the vars before the proc, these will get referenced by myProc

vector $tr, $rot, $sc;
myProc($tr,$rot,$sc);

print $tr;
print $rot;
print $sc;
}


i don't think you can pass references like this - you'll need an array to get them to pass:


proc myProc(vector $transform[])
{
...
... code that calculates the $transform
...
...
}

proc myCallingProc()
{
// cause you declared the vars before the proc, these will get referenced by myProc

vector $trans[];
myProc($trans);

print $trans;
}


-sunit

r1i
11-26-2006, 01:18 PM
I suggest to return an array or matrix and give this values in a second global variable (array or matrix as well, same size etc) and call your function in terms of changes of its parameters.
The "dirty-plug" feature is only accessible in API- programming, cause only there you can set references and pointers and the algorithm is only accessible there as class. This is to update your function, node, etc automatically when you change any linked (plugged) value.

hope this helps

r1i

CGTalk Moderation
11-26-2006, 01:18 PM
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.