Putting the "total" contactCount in a variable?

hi y'all

being a n00b, i need your expert help. My problem is the following:
i have some rigid bodies in my scene that collide with obstacle_1. What i want to do is get the total contact count over some extended period of time, not just per frame. If this total contactCount exceeds some threshold, my rigid body should "die" and respawn somewhere else.
What i have till now is the following:
i created a transform node called "rb1ContactData" and added some extra attributes to it, such as EXPR, contactCount, uniqueContactCount and totalContacts...

According to the if-loop, every time $contactCount is bigger than zero, it should increment the $totalContacts variable. But it only does it per frame, i.e. $totalContacts constantly jumps from 0 to 1 and back after every frame and i want to keep the total amount of contacts made ith obstacle_1...

What am I doing wrong? Your help would be much appreciated.
Alexander

below is some of the expression-code i use, if it could help clarify things...

rb1ContactData.EXPR =0;

// variables
string $myRigidBody = "obstacle_1";
int $contactCount;
int $uniqueContactCount;
int $totalContacts = 0;

// get $contactCount
$contactCount = getAttr($myRigidBody+".contactCount");

// compute $uniqueContactCount
if ($contactCount > 0)
{
$totalContacts = $totalContacts + 1;
string $array[] = rigidBody -q -contactName $myRigidBody;
string $flatArray[] = flattenStringArray($array);
$uniqueContactCount = size($flatArray);
}
else
{
$uniqueContactCount = 0;
}

// set interface attributes
rb1ContactData.contactCount = $contactCount;
rb1ContactData.uniqueContactCount = $uniqueContactCount;
rb1ContactData.totalContacts = $totalContacts;

it looks like you are allways resetting $totalContacts.
Try this instead:

rb1ContactData.EXPR =0;

// variables
string $myRigidBody = "obstacle_1";
int $contactCount;
int $uniqueContactCount;
int $totalContacts = getAttr rb1ContactData.totalContacts;

// get $contactCount
$contactCount = getAttr($myRigidBody+".contactCount");

// compute $uniqueContactCount
if ($contactCount > 0)
{
$totalContacts = $totalContacts + 1;
string $array[] = rigidBody -q -contactName $myRigidBody;
string $flatArray[] = flattenStringArray($array);
$uniqueContactCount = size($flatArray);
}
else
{
$uniqueContactCount = 0;
}

// set interface attributes
rb1ContactData.contactCount = $contactCount;
rb1ContactData.uniqueContactCount = $uniqueContactCount;
rb1ContactData.totalContacts = $totalContacts;

--g