Why isn't my integer value processed correctly with PHP in Rules? My articles have a field collection field and one of the fields is an integer. Users can add as many fields as they want. I'd like to reward them some userpoints, equal to the total value in their saved fields, but with an overall maximum of 5.

e.g. A user saves a first field with a value of 3. Therefore, he's awarded 3 points. When he saves another field with a value of 4 afterwards, he must be rewarded 5-3=2 points.

I wrote a rule that sums all the old and new values in the integer fields via a loop (the results are saved as variables 'Old total' and 'New total') when a new field collection is saved. Before I can grant userpoints to the user, I have to do some calculations to prevent the total amount of earned points to be larger than 5. I tried doing that by adding the following PHP code in the 'Process value' box of a 'Grant points to user' action:

if (old-total &gt; 5) {$value = 0;}
elseif (new-total &gt; 5) {$value = 5 - old-total;}
else {$value = [field-collection-item:field-my-integer];}
return $value;


However, when the action runs, the code seems to be ignored, because the value doesn't change at all. I don't get any errors.

What did I do wrong? How can I solve this?
I was able to solve this problem after finding the answer on my question 'How to use variables in a PHP evaluation in a rule?'.

Instead of activating the Rule when an event "After saving a new field collection item" occured, rather use "After updating existing content" and grant the Userpoints for the first Field Collection item in a different Rule. Afterwards, follow the instructions in the referenced answer and use the code underneath.

&lt;?php
if ($old_total &gt; 5) {return 0;}
elseif ($new_total &gt; 5) {return 5 - $old_total;}
elseif ($new_total == $old_total) {return 0;}
else {return $new_total;}
?&gt;