Static variables in HScript

   5511   6   2
User Avatar
Member
1391 posts
Joined: Dec. 2010
Offline
hello.
how i can create static variables in Hscript ?
like C++
static float myVar = 10.0f;

for example i want create a static variables by default value 10,then i want increases this variables in each time and send to TY from my object.

my custom Hscript :
{

static test = 10; //syntax error


test++;

return test;
}
https://www.youtube.com/c/sadjadrabiee [www.youtube.com]
Rabiee.Sadjad@Gmail.Com
User Avatar
Member
519 posts
Joined:
Offline
Why does it have to be static?
User Avatar
Member
94 posts
Joined: Dec. 2008
Offline
Pagefan
Why does it have to be static?

No offence pagefan, just ignore it, if you know the concept of static vars…

A static var is needed, when you want to have a local var, that keeps its value over several calls of a function…

( ops: Way too common to me to explain it properly… ops: )
If you can't script/program it, it's no good at all !
User Avatar
Member
401 posts
Joined:
Offline
Thanks for the explanation WhoDjini.

No Houdini doesn't have static variables as far as I know. Because it doesn't work that way.

If you want to increment the position of an object over time you have several options, including:
Use $TX + $F
Use chops
Use DOPs
Use POPs.


SOPs are procedural and don't have the concept of ‘memory’.
this is not a science fair.
User Avatar
Member
1391 posts
Joined: Dec. 2010
Offline
Ok .thanks.

i want create a variable by default value 1.when condition function equal to True , i want decrease the variable in each Frame.

for example :

{
myVar = 1;//i want just on time this variable setting up !

if($F>10)
myVar = myVar - 0.1;

out = clamp(myVar,0,1);

return out;
}


but in each frame again myVar = 1 !
https://www.youtube.com/c/sadjadrabiee [www.youtube.com]
Rabiee.Sadjad@Gmail.Com
User Avatar
Member
519 posts
Joined:
Offline
Something like this?

Attachments:
static_variable.hip (39.0 KB)

User Avatar
Member
1391 posts
Joined: Dec. 2010
Offline
thanks a lot.yes this is my purpose.
https://www.youtube.com/c/sadjadrabiee [www.youtube.com]
Rabiee.Sadjad@Gmail.Com
  • Quick Links