0
$\begingroup$

I am doing a little project using animation nodes and I used a script in the node tree but it keep saying "Local variable referenced before assignment",I used global before the variable and it say "Syntax error".

My code is just as simple as :

if Bool == 1 :
    Always = 1

here is my node: Nodes So what am I doing wrong?

$\endgroup$
2
  • $\begingroup$ a little bit more context would be helpful.., can you maybe add a screenshot to your question? And is the variable Bool declared somewhere? $\endgroup$ – Jacques Lucke Apr 18 '16 at 18:53
  • $\begingroup$ @JacquesLucke I edited the question. $\endgroup$ – Omar Emara Apr 19 '16 at 11:26
1
$\begingroup$

The problem is that you don't assign a value to the 'Always' variable in all cases.

AN takes your code and makes a function from it that is executed by the Invoke Subprogram node. The generated code looks like so:

enter image description here

Line 16 throws the error here because you haven't used 'Always' before. You can fix by changing your code to something like this:

if Bool == 1:
    Always = 1
else:
    Always = 0
$\endgroup$
5
  • $\begingroup$ well,I cant return a value if it is not equal to 1,I have an object that moves and if this object touches another object a text will appear but after the object go away and they not touching anymore the text will disappear,but I want it to stay after the first touch,so I was hopping hat this script will assign 1 to the Always variable after the first touch and it wont disappear.is there is another way to do that? $\endgroup$ – Omar Emara Apr 19 '16 at 11:40
  • $\begingroup$ Unfortunally this isn't really possible, because it is simulation: The current frame depends on the frames before. AN can't do simulation in nice ways. $\endgroup$ – Jacques Lucke Apr 19 '16 at 11:42
  • $\begingroup$ well,can I write a script that do something if the value is 1 in animation nodes,like creating a custom property? $\endgroup$ – Omar Emara Apr 19 '16 at 11:45
  • $\begingroup$ Yes sure. The problem is when do you want to reset this property when you go backwards in time. $\endgroup$ – Jacques Lucke Apr 19 '16 at 11:46
  • $\begingroup$ I won't use frames then,I will create the custom property if the objects touch. $\endgroup$ – Omar Emara Apr 19 '16 at 11:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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