Trying to use Rules to add energy to nodes that have none doesn't work. After hours of trying to figure out how to use rules with radioactivity, I finally found that the algorithm field requires a token replacement (unless you want to overwrite existing energy) and that the token must not evaluate to null. I think the offending lines of code begin around line 64 in radioactivity_rules.module:

  // FIXME: messy regexp
  // This will remove everything else other than 0-9 + - * / and functions sqrt, sin, cos, pow and tan
  preg_match_all("/([0-9\+\-\/\*\(\)\.\ ]|sqrt *\(|sin *\(|cos *\(|pow *\(|tan *\()/i", $algorithm, $matches);
  $clean = implode('', $matches[1]);
  
  ob_start();
  print eval('echo ' . $clean . ';');

If the token is [story_node:radioactivity-energy-1], the algorithm can be '[story_node:radioactivity-energy-1] + 10'. If the node has 5 in energy, 'echo $clean' would evaluate '5 + 10' and everything would be ok. But if the node has never received any energy, print eval would run echo on ' + 10', which is not a double and you're left with nothing, including no error messages.

Comments

escore’s picture

On closer inspection it seems that the tokens are not converted into values. $algorithm contains the string '[story_node:radioactivity-energy-1]' when there's no energy left, not a null value. Is this Radioactivity specific or is it me not knowing enough about how tokens work?

escore’s picture

Title: Adding energy using rules require existing energy » Rules: Doesn't check for empty token
escore’s picture

Gave up on rules (unfortunately) and instead wrote my own radioactivity plugin.

sutharsan’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

Issue triage: Closing issue, the 6.x branch is no longer maintained.

If you believe this issue is closed in error, feel free to re-open.