1
$\begingroup$

First of all, this is of course not my project. I am working on a project that has a similar idea and i want that for the sake of clarification. to briefly explain what i want, i need implementing the following simple pseudo program with animation node syntax

frame_number=0,frame_factorial=1   
while(1)
{
 frame_number++;
 frame_factorial*= frame_number;
}

So perhaps the simplest way to do it, is to create a math node with multiply mode, connection time info(frame number) to one input, then connecting the result back to the other input(feedback), which certainly doesn't work with animation node's syntax. so the question is how to retain a certain value calculated in a certain frame, in order to be used in the next frame? or when you have a cumulative calculation, like the one above?

for instance i thought the only way for that is to put 2 python script nodes at the beginning and at the end of a frame iteration, then use the script node at the end to save data to, for instance, csv file, then in the next frame read data from that csv file. however this is an impractical and unreasonable solution, i think their are of course other more practical methods, built in with animation nodes, isn't it?

$\endgroup$

1 Answer 1

2
$\begingroup$

I think you'd just be better off with an Expression node (Shift + A > Subprograms > Expression) with a Float input and the code factorial(x). It looks like this:

enter image description here

$\endgroup$
4
  • $\begingroup$ as i said, the purpose of my question is not just calculating factorial, again the question is how to retain a certain value calculated in a certain frame, in order to be used in the next frame? $\endgroup$
    – user8844
    Jan 19, 2018 at 22:45
  • 1
    $\begingroup$ unfortunately in AN every execution should be independent of the executions before. (otherwise all kinds of problems can start to appear when you skip frames, execute a tree twice etc..) So if you really need it, you have to somehow save and load the data yourself using a script node. $\endgroup$ Jan 19, 2018 at 23:46
  • 1
    $\begingroup$ i just did like that using 2 script nodes and using setattr(bpy, 'a') and getattr(bpy, 'a') commands, and it works :) thank you. i'm just suggesting to add a feature, since i know you are the developer, similar to this video: youtube.com/watch?v=wkjcHispZNY this is a graphical programming language called labview, it has some or even many similarities like AN. the thing i needed is exactly that"shift register", which retains variable from the past iteration of a while loop. $\endgroup$
    – user8844
    Jan 20, 2018 at 0:19
  • 1
    $\begingroup$ One thing to consider, even if you are able to apply data from one drone to the next, it’s important to remember that, in a production environment, frames are very likely rendered on a cluster where consecutive frames are unlikely to be rendered on the same machine, and at least sometimes out of order, so anything relying on in-order rendering is a pretty bad idea. $\endgroup$ Jul 22, 2018 at 22:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .