Integer not Adding up


#1

I have been messing with this runtime code for a while now so I am hoping someone here can help figure this out with me.

I am running a particle simulation that uses a goal of “1” and jumps from one curve to the next to write out a word in particles. I am trying to use this set of code in order to process the iterations. However, right now I have to key the goals on and off when the goalU hits 1.

What I want to do is automatically switch the goal Active off or on given what letter it should be on. However every time the total is processed to 1 it resets to 0 when it should add 1 to its total. It will only be 1 for the one frame that the goalU is above 1 then resets.

I hope that makes sense.


$go = primary_particleShape.goalU;
int $total = 0;
primary_particleShape.goalU += .01;
if(primary_particleShape.goalU > 1){
	primary_particleShape.goalU = 0;
	$total += 1;
}

print ($go + "
");
print ($total + "
");

:::PLAYBLAST :::
Playblast


#2

I don’t know anything about Maya scripting/programming but from my experience in other programs I’m guessing it’s because you are initialing total = 0 local to that code snippet. My guess is that this code gets executed every frame so when the conditions are met total only would be 1 for a a brief amount of time which is what you’re seeing. You don’t have a similar problem with the $go variable, since it is set to what must be a scene reference.


#3

Thats correct, your total is a local variable and is recreated for every evaluation step.
This approach would not work anyway because your total would be global for all particles, but I think you will need different values for them.

Instead of the local variable, simply use a per particle attribute.


#4

Ok, I’ll have to look into that.
Thank you guys for the help.


#5

another and very stable approach to this is to use the built in goalWeightPP.

basically make every letter a goal at the same time, add the appropriate number of goalWeightPP atts from the add attribute particle tab, then control goalWeightPP in your expression to make your particle object jump from one letter to another.


#6

I like this idea. I was looking at those attributes before, but I couldn’t wrap my head around it. I think I understand the concept now though. Thanks


#7

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.