Using Sin,Cos in Gateway Event scripts

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

Are you defining any new functions inside these script bodies?

I assume by this you mean you've tried

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)

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

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.

2 Likes

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

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

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

The result is the tag remaining null

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

The result is the tag remaining null

Please fix this for v8.3. Pretty please? :pray:

2 Likes

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.

1 Like

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

2 Likes