0

I'm trying to grant Userpoints to users with a Rule. The Rule first calculates two integer values 'New value' and 'Old value'. Debugging these numbers shows that there's no problem with them. Naturally, I tried awarding the points with an action "Grant points to a user" and I'm using the following code in the PHP evaluation:

if ($value > 5) {
  return 0;
}
else {
  return token_replace('[new-value]');
}

where the default $value is old-value. As the [new-value] token is available in the data selectors of the 'Points' section of the action, I suppose that one can use it in the PHP evaluation too. Therefore, after reading Token Replacements, I thought my code should work, but it doesn't: the Userpoints aren't granted to the user.

There's definitively something wrong with the Token, because the Rule is executed correctly when I use 1 instead of token_replace('[new-value]').

What am I doing wrong and how can I solve this?

0

1 Answer 1

0

I still don't know what went wrong, but I've solved the problem in an alternative way. Everything works fine when you follow the steps underneath.

  1. Save the integers Old value and New value as variables.
  2. Add a third variable Result. Thanks to step 1, one can use $old_value and $new_value in the PHP evalution of this variable. I've used this code:

    if ($old_value > 5) {
      return 0;
    }
    else {
      return $new_value;
    }
    
  3. Convert Value to an integer Final value.

  4. Award Final value Userpoints to the user of your choice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.