Jump to content


probably an easy syntax question


  • Please log in to reply
7 replies to this topic

#1 etudenc

etudenc

    Peon

  • Members
  • Pip
  • 25 posts
  • Joined: 29-September 10
  • Location:New York
  • Name:Phil Cole

Posted 25 July 2012 - 11:50 AM

Would someone be kind enough to tell me why the top expression works but the bottom one doesn't? Am I supposed to format a user-defined variable differently inside a function?

# working
{
return vector("[1, 2, 3]")[0] ;
}

#not working :(
{
float dirX = 1 ;
float dirY = 2 ;
float dirZ = 3 ;

return vector("[dirX, dirY, dirZ]")[0] ;
}

I've tried all kinds of variations such as:
return vector([dirX dirY dirZ]) ; (no commas)
return vector(["dirX", "dirY", "dirZ"]) ; (added quotes around each variable)
return vector([("dirX"), ("dirY"), ("dirZ")]) ; (quotes and parentheses)
return vector("[(dirX), (dirY), (dirZ)]")) ;
return vector("[(dirX) (dirY) (dirZ)]")) ; (no commas)
return vector("[(dirX)], [(dirY)], [(dirZ)]") ;
return vector("[dirX], [dirY], [dirZ]") ;

but no go.

Thanks for any pointers!

Edited by etudenc, 25 July 2012 - 12:51 PM.


#2 rafaelfs

rafaelfs

    Initiate

  • Members
  • PipPip
  • 136 posts
  • Joined: 16-September 10
  • Location:Toronto
  • Name:Rafael Santos

Posted 25 July 2012 - 12:29 PM

I'm no vex expert, but have you tried this?

return vector([dirX, dirY, dirZ])[0];

Cheers
Toronto - ON
My Houdini playground

#3 etudenc

etudenc

    Peon

  • Members
  • Pip
  • 25 posts
  • Joined: 29-September 10
  • Location:New York
  • Name:Phil Cole

Posted 25 July 2012 - 12:43 PM

View Postrafaelfs, on 25 July 2012 - 12:29 PM, said:

I'm no vex expert, but have you tried this?

return vector([dirX, dirY, dirZ])[0];

Cheers

Thanks rafaelfs, unfortunately I have but no luck. I'll edit my post to include the variations I've tried. Maybe in the process I'll land on the right one!

#4 rafaelfs

rafaelfs

    Initiate

  • Members
  • PipPip
  • 136 posts
  • Joined: 16-September 10
  • Location:Toronto
  • Name:Rafael Santos

Posted 25 July 2012 - 12:54 PM

BTW, what are you trying to do?
Toronto - ON
My Houdini playground

#5 anim

anim

    Houdini Master

  • Members
  • PipPipPipPip
  • 912 posts
  • Joined: 23-August 07
  • Location:Slovakia, Bratislava
  • Name:Tomas Slancik

Posted 25 July 2012 - 12:55 PM

this looks like Hscript
try this

{
float dirX = 1 ;
float dirY = 2 ;
float dirZ = 3 ;

return vector( "[" + dirX + "," + dirY + "," + dirZ + "]" )[0] ;
}

EDIT: but as rafael said, tell us what you are trying to do, you may get answer to your actual problem instead of jus little fix of your approach which may not be the most efficient

Edited by anim, 25 July 2012 - 12:57 PM.

Tomas Slancik
Generalist
Slovakia

#6 etudenc

etudenc

    Peon

  • Members
  • Pip
  • 25 posts
  • Joined: 29-September 10
  • Location:New York
  • Name:Phil Cole

Posted 25 July 2012 - 01:17 PM

View Postanim, on 25 July 2012 - 12:55 PM, said:

this looks like Hscript
try this

{
float dirX = 1 ;
float dirY = 2 ;
float dirZ = 3 ;

return vector( "[" + dirX + "," + dirY + "," + dirZ + "]" )[0] ;
}

EDIT: but as rafael said, tell us what you are trying to do, you may get answer to your actual problem instead of jus little fix of your approach which may not be the most efficient

Thank you, that worked! I was a long way from the answer!

I don't know if this is the most efficient way of doing things but for my current project I decided to create a control node (a NULL) so that I can add and centralize some parameters. Using some expressions in each parameter, I'm able to
- specify two points on whatever geo is plugged in to a transform SOP
- get their respective positions
- find the direction (a vector)

I want to normalize the direction but I got stuck trying to figure out how to normalize a value coming from a parameter so this is my roundabout way of making it happen. I tried passing the direction vector to a point attribute but the normalize node in the VOP SOP isn't giving me predictable results, so writing an expression seems like the next thing to try.

Thanks again!

#7 rafaelfs

rafaelfs

    Initiate

  • Members
  • PipPip
  • 136 posts
  • Joined: 16-September 10
  • Location:Toronto
  • Name:Rafael Santos

Posted 27 July 2012 - 05:39 AM

View Postetudenc, on 25 July 2012 - 01:17 PM, said:

Thank you, that worked! I was a long way from the answer!

I don't know if this is the most efficient way of doing things but for my current project I decided to create a control node (a NULL) so that I can add and centralize some parameters. Using some expressions in each parameter, I'm able to
- specify two points on whatever geo is plugged in to a transform SOP
- get their respective positions
- find the direction (a vector)

I want to normalize the direction but I got stuck trying to figure out how to normalize a value coming from a parameter so this is my roundabout way of making it happen. I tried passing the direction vector to a point attribute but the normalize node in the VOP SOP isn't giving me predictable results, so writing an expression seems like the next thing to try.

Thanks again!

Let me see if I understand: having point A and point B, you want to be able to plug a transform SOP to point A so that it automatically moves to point B? Or do you just want to find the vector that would do such operation?

Both cases are relatively ease to figure out with either a VOP SOP or a point SOP and some expressions...

Cheers
Toronto - ON
My Houdini playground

#8 Fabiano Berlim

Fabiano Berlim

    Initiate

  • Members
  • PipPip
  • 185 posts
  • Joined: 24-June 08
  • Location:Brazil
  • Name:Fabiano Berlim

Posted 27 July 2012 - 03:39 PM

Variables inside strings should be called with $.
Example:
{
float dirX=0;
float dirY=1;
float dirZ=2;
return vector("[$dirX,$dirY,$dirZ]")[2];
}

Edited by Fabiano Berlim, 27 July 2012 - 06:04 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users