ForEach SOP stop condition based on inner detail attribute

   4385   3   2
User Avatar
Member
271 posts
Joined: March 2012
Offline
Hi all,
I'm having a horrible time diagnosing why something wasn't working as expected (in fact, generally I've found debugging foreach SOPs agonising).

First of all, I have a foreach SOP inside a solver. (I don't know whether this would cause any problems, but I couldn't find reference to anything about this being an issue) that foreach is set to Each Number and Merge Results is switched off. So, it should just alter the geometry then feed it back into itself until the stop condition. Standard stuff.
For the stop condition, I was looking up a detail attribute inside the loop
detail(“whatever_node”, “stop”, 0)
…and this is where the problem arises. This just does not work and I do not know why.
I'm unsure how this gets evaluated. It seems like stop condition is evaluating all the code leading up to the stop condition detail attribute, but then not implementing it.

I've attached a simple scene showing what I'm talking about. In the foreach node there is a wrangle that sets the stop condition. It should increment the variable, then do the test to see if it should stop.
As you can see by looking at the details view of the foreach1 node, the count isn't incremented at all and the execution immediately stops.

I think this is because the stop condition is evaluated before node execution. This is different to a classic programming for loop. You'd have a condition, the loop starts to execute, you do a bunch of things, and then you perform a comparison to see if you should stop.
This looks at what the condition would be had you executed, then stops execution (in this case) prematurely.
I may just be tired…but how do I get around this?

tldr; Is there a way to get the foreach to evaluate the stop condition after each loop, not before?

Attachments:
foreach.hip (61.5 KB)

User Avatar
Member
96 posts
Joined: May 2008
Offline
Yup, seems like the stop condition is evaluated first. So I'd probably just do something like if(detail(“attribwrangle2”, “stop”,0)==2, 1, 0) and raise the stop attribute twice. Hardly elegant, but probably the only way (or make your test inside the foreach so that it only sets “stop” _after_ it ran successfully)
User Avatar
Member
271 posts
Joined: March 2012
Offline
ripclaw
…(or make your test inside the foreach so that it only sets “stop” _after_ it ran successfully)

This is why I'm confused, as it essentially already does it. It's the last thing to be done in the loop.
What is really needed is the forloop to have an option to check the condition after it performed the iteration, not before as it currently does.
User Avatar
Member
96 posts
Joined: May 2008
Offline
Yeah, no, what I meant was to create for example instead of “stop” another attribute called “stop_nexttime” and then check that one and if that is set, set “stop”. Yeah, it's convoluted, but that'd work I guess.
  • Quick Links