Mzigaib Posted May 5, 2014 Share Posted May 5, 2014 Newb question! If I go to aliases and variables and create a function like: float test(float x, float y) { float result = x+y; return $result; } And to test it I go to texport I do like: echo `test(3,5)` I get: Expression error: Undefined variable I was expecting 8, what am I doing wrong? Thanks! Quote Link to comment Share on other sites More sharing options...
graham Posted May 5, 2014 Share Posted May 5, 2014 You don't need the $ before result on your return line. Remove it and it will work correctly. Quote Link to comment Share on other sites More sharing options...
Mzigaib Posted May 5, 2014 Author Share Posted May 5, 2014 (edited) Thanks Graham! Now I want to create a function for my camera focus that works like a ramp based on distance so I want to get the distance between my camera and the target and divide it with a max distance and then I remap the values later so for that I did this: float focus (vector cam,vector target,float maxdist) { vector direction = cam-target; float dist = length(direction); float ndist = dist / maxdist; return ndist; } I can remap the values later but if I go to textport to test it like this: echo `focus(vector3(1,1,1),vector3(5,5,5),5)` Houdini tells me this: Expression error: Invalid number of arguments for function What am I doing wrong? Thanks again! Edited May 5, 2014 by Mzigaib Quote Link to comment Share on other sites More sharing options...
Mzigaib Posted May 5, 2014 Author Share Posted May 5, 2014 [sOLVED]! I made a modification and it worked: float focus (float maxdist,float near,float far) { vector cam = vector3(ch("/obj/cam1/tx"),ch("/obj/cam1/ty"),ch("/obj/cam1/tz")); vector target = vector3(ch("/obj/target/tx"),ch("/obj/target/ty"),ch("/obj/target/tz")); float dist = distance(cam[0],cam[1],cam[2],target[0],target[1],target[2]); float ndist = clamp(maxdist/dist,near,far); float finalfocus = fit01(ndist,near,far); return finalfocus; } I hope it helps someone. Cheers! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.