Your goal and the presented code aren't clear to me. The consequence (after then) contains calls to static/class methods (Box.setX()) which isn't going to change anything in your fact object. The call b.setX() might change your object, but this depends on what the class method Box.getX() returns.

Assuming Drools 5, a typical consequence would look like
   b: Box(...)
then
   modify( b ){
      setX( ... )
   }
end

-W

On Sat, Aug 8, 2009 at 1:48 AM, sonia <robotnic+drools@gmail.com> wrote:
Hello

I want to achieve this:
box1.setX(0)
box2.setX(box1.size());
box2.setX(box1.size + box2.size)
...

I want to do it with rules, and would like to know what's the best
method of initializing (or any other operation with varying data) a
group of objects

rule "init box"
 when
  b : Box( x == -1)
 then
  b.setX(Box.getX());
  Box.setX( Box.getX() + b.size);
end

This does not work.
A single box object is matched several times instead of different box objects.
What is happening? how come a single box object is matched several
times? Why doesnt drools choose other instances of box?

What do I need to do to initialize all boxes, once for every box?

Thank you.

--
robosonia
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users