Input in Imperative Function

Hi Fam,

Why is it that an input reads null inside an Imperative Function?
For example:

This would work, with input being driven by any integer manually or by slider.
input;
output = [Imperative]
{
if (input == 0)
{
output = “ZERO”;
}
return output;
}
Successfully returns “ZERO”

However, once I turn it into a function:
def GOGO(input) // I’ve tired input:var, input:var[], input:int, intput:int[], input, etc…

output = [Imperative]
{
if (input == 0)
{
output = “ZERO”;
}
return output;
}
}

GOGO(0) returns null.

Help?

Try initialising your variables :

def GOGO(input:int)
{
	output = [Imperative]
	{
		c = "Nothing to see here";
		if (input == 0)
		{
			c = "ZERO";
		}
		return = c;
	};
	return = output;
};
1 Like

Additionally, everytime I restart my dynamo I get an error for that code block saying Variable isn’t defined yet. Seems like a bug. Using the latest version of Dynamo 2.01.5

Hey there thanks for the response but as stated above I already tried all combinations of initializing my variables.

It worked on my version of Dynamo (using 2.01 too).

Without initialization :

2018-07-27%2016_55_06-Dynamo

1 Like

I tried on another machine and it seems to be working now. Very strange why does a code block behave differently on another machine? Anyways looking at your code, couldn’t it be simpler to do this? Why do you have different return outputs and two ending semicolons?

2 Likes

I have found that sometimes I need to restart Dynamo for my imperative blocks to execute correctly. It seems that after being executed a few times they get tired and need a restart :slight_smile:

2 Likes

Hi All ! I have the same issue here and can’t reach a solution. Any help is needed :slight_smile:

i always get ‘1’ no matter what the input was .