Hscript inline function

   5107   5   0
User Avatar
Member
12 posts
Joined: Nov. 2007
Offline
This is killing me… how in the world do i create an hscript function attached to a value to return a different number based on frame? i.

if ($F == 1 ) then
set var = 1
else
set var = 2
endif

return var

please help! I can'f find documentation anywhere that works
User Avatar
Member
8773 posts
Joined: July 2007
Offline
in HScript expressions it's:
if($F == 1, 1, 2)
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
12 posts
Joined: Nov. 2007
Offline
right but I don't want a simple expression…… I have 5 if statements that I want to evaluate and return different values.

so something like this:
if ($F == 1, 1, 0)

will give me 1 if it's true and 0 if it's false

if i do this:
if($F == 1, 1, 0) || if($F == 5, 10, 0)

it will only return a 1 or a 0 not 1 or 10….. I want to do an inline function but I can't figure out the sytanx in hscript. I know how to create a python function to do this but not hscript
User Avatar
Member
8773 posts
Joined: July 2007
Offline
then you can either use nested expressions
if($F == 1, 1, if($F == 2, 4, if($F == 3, 6, if($F == 4, 8,if($F == 5, 10, 0)))))
or inline syntax would be
{
float v = 0;
if($F == 1) {v = 2;}
if($F == 2) {v = 4;}
if($F == 3) {v = 6;}
if($F == 4) {v = 8;}
if($F == 5) {v = 10;}
return v;
}
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
12 posts
Joined: Nov. 2007
Offline
nice! thank you! it never occurred to me to use the false statement as a way to trigger another conditional……. I like the inline as it feels easier to read…..

Thanks man you are the best!
User Avatar
Member
678 posts
Joined: July 2005
Offline
You can write your own expression functon. Just go to EDIT -> ALIASES and VARIABLES -> Expressions and write whatever you want.

Example:

float test(float frame, string text)
{
float len = strlen(text);

if(frame <= 10)
{
return 2;
}
else if(frame > 10 && frame <= 20)
{
return 21 / len;
}
else if(frame > 20 && frame <= 30)
{
return 3.4;
}
else
{
return len;
}
}


Then you can call this expression from anywhere by just typing function name and pasing parameters. Note that you don't need to use $ sign to call your function.


test($F, “Hello”)
  • Quick Links