# Input in Imperative Function

**URL:** <https://forum.dynamobim.com/t/input-in-imperative-function/24225>\
**Category:** DesignScript\
**Created:** [July 27, 2018, 2:22pm UTC](https://forum.dynamobim.com/t/input-in-imperative-function/24225 "2018-07-27T14:22:45Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![RVT](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@RVT](https://forum.dynamobim.com/u/RVT)\
**Post date:** [July 27, 2018, 2:22pm UTC](https://forum.dynamobim.com/t/input-in-imperative-function/24225/1 "2018-07-27T14:22:45Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![mellouze](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@mellouze](https://forum.dynamobim.com/u/mellouze)\
**Post date:** [July 27, 2018, 2:50pm UTC](https://forum.dynamobim.com/t/input-in-imperative-function/24225/2 "2018-07-27T14:50:48Z")

</div>

Try initialising your variables :

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

---

<div class="post-metadata">

**Author:** ![RVT](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@RVT](https://forum.dynamobim.com/u/RVT)\
**Post date:** [July 27, 2018, 2:51pm UTC](https://forum.dynamobim.com/t/input-in-imperative-function/24225/3 "2018-07-27T14:51:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RVT](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@RVT](https://forum.dynamobim.com/u/RVT)\
**Post date:** [July 27, 2018, 2:52pm UTC](https://forum.dynamobim.com/t/input-in-imperative-function/24225/4 "2018-07-27T14:52:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mellouze](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@mellouze](https://forum.dynamobim.com/u/mellouze)\
**Post date:** [July 27, 2018, 2:54pm UTC](https://forum.dynamobim.com/t/input-in-imperative-function/24225/5 "2018-07-27T14:54:43Z")

</div>

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

 ![2018-07-27%2016_53_58-Dynamo](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/d/0d88664504016fba06094793d17a45e92baa83df.png)

---

<div class="post-metadata">

**Author:** ![mellouze](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@mellouze](https://forum.dynamobim.com/u/mellouze)\
**Post date:** [July 27, 2018, 2:55pm UTC](https://forum.dynamobim.com/t/input-in-imperative-function/24225/6 "2018-07-27T14:55:58Z")

</div>

Without initialization :

![2018-07-27%2016_55_06-Dynamo](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/4/74c967406ecdc0ed5e13eb74eda144492f46212f.png)

---

<div class="post-metadata">

**Author:** ![RVT](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@RVT](https://forum.dynamobim.com/u/RVT)\
**Post date:** [July 28, 2018, 12:35am UTC](https://forum.dynamobim.com/t/input-in-imperative-function/24225/7 "2018-07-28T00:35:44Z")

</div>

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?

 ![Screenshot_1](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/6/86d1d336ac3bb486b3374659a623ed5545bbdb7e.png)

---

<div class="post-metadata">

**Author:** ![Renzoj14](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/renzoj14/32/49196_2.png) [@Renzoj14](https://forum.dynamobim.com/u/Renzoj14)\
**Post date:** [August 4, 2018, 12:57pm UTC](https://forum.dynamobim.com/t/input-in-imperative-function/24225/8 "2018-08-04T12:57:22Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![Ahmed\_Ramy](https://avatars.discourse-cdn.com/v4/letter/a/f17d59/32.png) [@Ahmed\_Ramy](https://forum.dynamobim.com/u/Ahmed_Ramy)\
**Post date:** [July 27, 2022, 10:00am UTC](https://forum.dynamobim.com/t/input-in-imperative-function/24225/9 "2022-07-27T10:00:12Z")

</div>

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

> [@Code block while loop](https://forum.dynamobim.com/t/code-block-while-loop/79167):
>
> Hi All! I am trying to get a list of integers based on a counter. Here is a shot of my script and I can’t get it done. Any help ??

---

<div class="post-metadata">

**Author:** ![Ahmed\_Ramy](https://avatars.discourse-cdn.com/v4/letter/a/f17d59/32.png) [@Ahmed\_Ramy](https://forum.dynamobim.com/u/Ahmed_Ramy)\
**Post date:** [July 27, 2022, 10:02am UTC](https://forum.dynamobim.com/t/input-in-imperative-function/24225/10 "2022-07-27T10:02:28Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/9/e93ac97d01d689a3bfaea99fdde82d2b8a3c986a.png)
