Integer not Adding up

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
  08 August 2013
Integer not Adding up

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 + "\n");
print ($total + "\n");


Last edited by jhealyvfx : 08 August 2013 at 12:20 AM.
  08 August 2013
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.
Rendering with Pixels
  09 September 2013
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.
__________________ -
  09 September 2013
Ok, I'll have to look into that.
Thank you guys for the help.
  09 September 2013
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.
  09 September 2013
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
  09 September 2013
Thread automatically closed

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.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 05:30 PM.

Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.