Does anyone know how to assign value of a varible inside a precedure to global variable??
example:
instead of
foo(){
run(“setenv VAR=10”);
}
is it possible to do
foo(){
i=10;
run(“setenv VAR…?”); // assign VAR to i
}
coding help again
4595 6 0- xusword
- Member
- 11 posts
- Joined: July 2005
- Offline
- EigenAlex
- Member
- 639 posts
- Joined: July 2005
- Offline
How about setting your expression so that you can feed your the global variable into your custom expression function?
foo(bar)
{
i = bar;
return i;
}
So that when you'd type “foo($myGlobalVar)” in your parameter?
I think that approach would be better for most cases.
But otherwise, assuming that you have the global variable already set, you can simply call it from when in your custom expression function like:
i = $myGlobalVar;
EDIT: please also note that if you don't declare type, Houdini will assume a float type. Otherwise, other type available are: string, vector, and matrix
Anyhow, hope that helped.
Alex
foo(bar)
{
i = bar;
return i;
}
So that when you'd type “foo($myGlobalVar)” in your parameter?
I think that approach would be better for most cases.
But otherwise, assuming that you have the global variable already set, you can simply call it from when in your custom expression function like:
i = $myGlobalVar;
EDIT: please also note that if you don't declare type, Houdini will assume a float type. Otherwise, other type available are: string, vector, and matrix
Anyhow, hope that helped.
Alex
- xusword
- Member
- 11 posts
- Joined: July 2005
- Offline
- xusword
- Member
- 11 posts
- Joined: July 2005
- Offline
ok guess I have to state my problem again
i wrote my own interpolation function and store the interplated function as a vector
I only want to interpolate my function once in a curve so I store it inside a global variable
for example
some object's translate x, y, z is map to this foo
$polyReady is initially set to -1
vector foo(){
if ($polyReady < 0){
//calculate p1 to p4, they are sample points for our interpolations
run(“setenv $poly=Interp(p1,p2,p3,p4)”);// PROBLEM: cannot pass p1~p4 inside this code…
run(“setenv $polyReady=1”);
}
if ( reach the end of this curve ){
$polyReady = -1;
// WHEN THIS FUNCTION IS CALLED, IT WOULD RE-CALCULATE p1~p4
}
return polyApply($poly, $FF);
}
i wrote my own interpolation function and store the interplated function as a vector
I only want to interpolate my function once in a curve so I store it inside a global variable
for example
some object's translate x, y, z is map to this foo
$polyReady is initially set to -1
vector foo(){
if ($polyReady < 0){
//calculate p1 to p4, they are sample points for our interpolations
run(“setenv $poly=Interp(p1,p2,p3,p4)”);// PROBLEM: cannot pass p1~p4 inside this code…
run(“setenv $polyReady=1”);
}
if ( reach the end of this curve ){
$polyReady = -1;
// WHEN THIS FUNCTION IS CALLED, IT WOULD RE-CALCULATE p1~p4
}
return polyApply($poly, $FF);
}
- xusword
- Member
- 11 posts
- Joined: July 2005
- Offline
also
there is another place I need to update global variable
my functions doesn't keep track of which frames does what
so after all the action sequence are finished, I want the object stay at the same position until it is activated again
Therefore I have to update the global variable, the default position of this object…
for example
some function's translate x, y, z are mapped to this function foo
vector foo(){
if ($activate>0){
// calculate x, y, z
run(“setenv DefPos=`vector(x,y,z)`”);// this line doesn't work because it doesn't reconize x, y, z
return vector(x,y,z);
}
else{
return $DefPos;
}
}
guess I can remember the frame number and if inactivate, use the stored frame number instead of the actual frams number, but it would be so inefficient because it would do unnecesssary calculation
there is another place I need to update global variable
my functions doesn't keep track of which frames does what
so after all the action sequence are finished, I want the object stay at the same position until it is activated again
Therefore I have to update the global variable, the default position of this object…
for example
some function's translate x, y, z are mapped to this function foo
vector foo(){
if ($activate>0){
// calculate x, y, z
run(“setenv DefPos=`vector(x,y,z)`”);// this line doesn't work because it doesn't reconize x, y, z
return vector(x,y,z);
}
else{
return $DefPos;
}
}
guess I can remember the frame number and if inactivate, use the stored frame number instead of the actual frams number, but it would be so inefficient because it would do unnecesssary calculation
- Mario Marengo
- Member
- 941 posts
- Joined: July 2005
- Offline
Hi xus,
Concatenate the command and the variable (using the ‘+’ operator) to form the final command string, like this:
foo()
{
float i=10;
run(“setenv VAR = ” + i + “; varchange”);
}
The second command “varchange” is there to force a recook of all operators which reference $VAR – otherwise the value of $VAR would change, but things wouldn't necessarily update.
And similarly:
vector foo() {
if ($activate>0) {
// calculate x, y, z
run(“setenv DefPosX = ” + x);
run(“setenv DefPosY = ” + y);
run(“setenv DefPosZ = ” + z);
run(“varchange”);
}
return vector3(x,y,z);
}
Note that even though the function's return type is vector, the actual return value is constructed with vector3(). Also note that the global is stored as three separate components, otherwise it would end up with the string-formatted version of the vector: something like "“ instead of the actual numerical values. Wherever you need to use the global ”DefPos" in vector form, you'd use the expression vector3($DefPosX,$DefPosY,$DefPosZ).
P.S: Are you “KeKe” over at the od forum? (just curious)
Cheers!
xusword
is it possible to do
foo(){
i=10;
run(“setenv VAR…?”); // assign VAR to i
}
Concatenate the command and the variable (using the ‘+’ operator) to form the final command string, like this:
foo()
{
float i=10;
run(“setenv VAR = ” + i + “; varchange”);
}
The second command “varchange” is there to force a recook of all operators which reference $VAR – otherwise the value of $VAR would change, but things wouldn't necessarily update.
And similarly:
vector foo() {
if ($activate>0) {
// calculate x, y, z
run(“setenv DefPosX = ” + x);
run(“setenv DefPosY = ” + y);
run(“setenv DefPosZ = ” + z);
run(“varchange”);
}
return vector3(x,y,z);
}
Note that even though the function's return type is vector, the actual return value is constructed with vector3(). Also note that the global is stored as three separate components, otherwise it would end up with the string-formatted version of the vector: something like "“ instead of the actual numerical values. Wherever you need to use the global ”DefPos" in vector form, you'd use the expression vector3($DefPosX,$DefPosY,$DefPosZ).
P.S: Are you “KeKe” over at the od forum? (just curious)
Cheers!
- xusword
- Member
- 11 posts
- Joined: July 2005
- Offline
-
- Quick Links