# Using Sin,Cos in Gateway Event scripts

**URL:** <https://forum.inductiveautomation.com/t/using-sin-cos-in-gateway-event-scripts/66258>\
**Category:** Ignition\
**Tags:** ignition81, scripting\
**Created:** [November 8, 2022, 9:02pm UTC](https://forum.inductiveautomation.com/t/using-sin-cos-in-gateway-event-scripts/66258 "2022-11-08T21:02:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Molto\_Benne](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@Molto\_Benne](https://forum.inductiveautomation.com/u/Molto_Benne)\
**Post date:** [November 8, 2022, 9:02pm UTC](https://forum.inductiveautomation.com/t/using-sin-cos-in-gateway-event-scripts/66258/1 "2022-11-08T21:02:59Z")

</div>

Hi, I'm trying to use sin and cos in a gateway event script (specifically a timer script). For some reason neither import math and using math.sin() nor just using sin() works. Is there something I'm missing like a library or a setting that might allow these functions? Thank you.

edit: typo in my post \* import

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [November 8, 2022, 9:03pm UTC](https://forum.inductiveautomation.com/t/using-sin-cos-in-gateway-event-scripts/66258/2 "2022-11-08T21:03:29Z")

</div>

Are you defining any new functions inside these script bodies?

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [November 8, 2022, 9:08pm UTC](https://forum.inductiveautomation.com/t/using-sin-cos-in-gateway-event-scripts/66258/3 "2022-11-08T21:08:24Z")

</div>

> [@Molto\_Benne](#):
>
> important math

I assume by this you mean you've tried

```auto
import math
math.sin()

```

? (it's best to state explicitly what you've tried with code examples and what is not working to avoid more questions, assumptions, and guessing)

---

<div class="post-metadata">

**Author:** ![Molto\_Benne](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@Molto\_Benne](https://forum.inductiveautomation.com/u/Molto_Benne)\
**Post date:** [November 8, 2022, 9:11pm UTC](https://forum.inductiveautomation.com/t/using-sin-cos-in-gateway-event-scripts/66258/4 "2022-11-08T21:11:45Z")

</div>

Yes, I am defining a function and within it I am using sin and cos.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [November 8, 2022, 9:13pm UTC](https://forum.inductiveautomation.com/t/using-sin-cos-in-gateway-event-scripts/66258/5 "2022-11-08T21:13:42Z")

</div>

Gateway event scripts, for complicated legacy reasons, use extremely outdated Python scoping rules.

Either do your imports _inside the functions you're defining_, or (preferred) write your functions in the project library and just call into the project library from the gateway event scripts.

---

<div class="post-metadata">

**Author:** ![Molto\_Benne](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@Molto\_Benne](https://forum.inductiveautomation.com/u/Molto_Benne)\
**Post date:** [November 8, 2022, 9:18pm UTC](https://forum.inductiveautomation.com/t/using-sin-cos-in-gateway-event-scripts/66258/6 "2022-11-08T21:18:17Z")

</div>

Yes that was a typo in my post. Thank you.

as for what I have tried, I have tried the following

```auto
test=cos(0)
system.tag.writeBlocking("[default]Tags/test", test)

```

The result is the tag remaining null

```auto
import math
test=math.cos(0)
system.tag.writeBlocking("[default]Tags/test", test)

```

The result is the tag remaining null

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 8, 2022, 10:34pm UTC](https://forum.inductiveautomation.com/t/using-sin-cos-in-gateway-event-scripts/66258/7 "2022-11-08T22:34:53Z")

</div>

> [@paul-griffith](#):
>
> Gateway event scripts, for complicated legacy reasons, use extremely outdated Python scoping rules.

Please fix this for v8.3. Pretty please? 🙏

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [November 8, 2022, 11:19pm UTC](https://forum.inductiveautomation.com/t/using-sin-cos-in-gateway-event-scripts/66258/8 "2022-11-08T23:19:44Z")

</div>

That's the plan.  
In addition, migrating them to 'extension function' style, so they're more ergonomic to the rest of the platform.  
And serializing the individual files as .py files on disk (somehow).  
And an overall UI refresh, especially w.r.t inheritance.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 9, 2022, 1:26am UTC](https://forum.inductiveautomation.com/t/using-sin-cos-in-gateway-event-scripts/66258/9 "2022-11-09T01:26:07Z")

</div>

> [@paul-griffith](#):
>
> more ergonomic

And more explicit about what variables are handed off. The best part of the extension function system.
