View Full Version : Pflow scripting questions
I'm getting into pflow scripting for a certain task, but am having trouble with the differences between regular maxscript and pflow scripts.
1. How do i call a function from a callback without putting the function within the callback itself!?
2. Why can't I have global variables outside of the callbacks?
3. I'm choosing random positions along a spline to position the particles at frame 0, but the position changes every time the script is evaluated, where I thought random used a constant seed. This probably has to do with me calling it from the callback rather than a function (see problem 1). This is far easier to solve however, just use the particle index and normalize, vs using random 0 1.
Any input would be appreciated.
01-05-2011, 11:03 PM
When you say callbacks are you refering to the script op event handlers? or are you using a callback mechanism within a script op?
If you are talking about the event handlers, you can initialize global variables from within the 'on Init pCont do' handler.
As for generating random numbers from within pflow script ops there are supplied rand functions that you should use instead of the random x x method. They are:
-- <float>rand01() // get random number from interval [0, 1]
-- <float>rand11() // get random number from interval [-1, 1]
-- <float>rand55() // get random number from interval [-0.5, 0.5]
-- <integer>rand0X <integer>maxNumber // get random integer number from interval [0..maxNumber]
on Proceed pCont do
count = pCont.NumParticles()
for i in 1 to count do
theRandNum = pCont.rand01()
Also if you want to make sure a eval is called only once to a particle in an event (instead of at every integration step) look at the pCont.IsParticleNew function, works well with an if/then bool to check if a particle has newly arrived to the event, if bool condition is met it will continue, if not, else or nothing.
01-07-2011, 07:33 PM
Am I way off topic? Are you talking Script Ops or using maxscript to control pFlow?
My apologies, i'm jumping between several projects. I am talking about scripted ops, and I am talking about the built-in callbacks (on init pCont do, etc.).
The random thing is great, but I still don't get the variable thing. Why can't I have a global or "local myVar" at the top of the script and write to that?
01-13-2011, 10:43 PM
As to why you can't have a global/local variable that is outside a handler? That I do not really have an answer for. Oleg, Bobo, Mr. Ruff, or Brandon Davis maybe able to explain why?
Do you need to see those variables outside of the script operator, like to be read be a standard maxscript or something similar?
Putting them in the initializer (on Init...) is generally where they go if you want to set them up prior to the proceed (on Proceed...). You can to of course put them within the proceed too, in fact you can typically stick the whole thing within the proceed without issues.
01-13-2011, 10:43 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.