# Time tracking using Gateway Timer Script

**URL:** <https://forum.inductiveautomation.com/t/time-tracking-using-gateway-timer-script/94076>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [August 1, 2024, 6:19pm UTC](https://forum.inductiveautomation.com/t/time-tracking-using-gateway-timer-script/94076 "2024-08-01T18:19:03Z")\
**Posts on this page:** 1\
**Showing post:** 10

<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:** [August 1, 2024, 8:30pm UTC](https://forum.inductiveautomation.com/t/time-tracking-using-gateway-timer-script/94076/10 "2024-08-01T20:30:28Z")

</div>

The reason for that is complicated and hard to explain - basically, legacy code baggage. The easiest fix (and a good practice overall) is to move the function you're defining into the project library. That is, literally take the whole block of code you have starting from `def` and put it into a new project library script. Name it whatever you want, and then call it from your timer script using `yourScriptLibraryName.updateVFD1()`.

That aside, you've got some syntax issues/misunderstandings that I'll correct here, but I'll again recommend a basic Python course.

```python
run_state1 = float
memory_state1 = float

```

Python doesn't require you to initialize variables before you use them, with or without type information. You can just declare a variable with a value, and the type is implicit. Drop these lines completely.

```python
def updateVFD1(run_state1, memory_state1):

```

You only need to write `run_state1`, `memory_state1` (or anything else) at the top of your function _if it's a parameter your function expects_.  
That is, look at these different function definitions:

```python
def addTwo(a):
	return a + 2

def multiplyAndAddSomething(a, b):
	something = 13
	return (a * b) + something

def doSomething():
	print "I did something!"

```

You don't need to (and shouldn't) define a method as accepting parameters if it doesn't actually need them. In your case, you're overwriting any possible input parameters _anyways_, so it's completely pointless.

> [@VerminProgrammer](#):
>
> `print "Original value:", run_state1`

`print` statements, when code is executed on the gateway, go straight to the `wrapper.log` file, which can be annoying to get to. Prefer using `system.util.getLogger` when writing gateway scripts, so you can see the output directly in the gateway webpage.  
More info here: [Event Configuration Print Out to debug - #5 by PGriffith](https://forum.inductiveautomation.com/t/event-configuration-print-out-to-debug/60091/5)

> [@VerminProgrammer](#):
>
> ```python
> memory_state1 = run_state1
> 
> ```

There's no need to reassign the value of a local variable. This won't do anything to the tags - it's just having your CPU spin for a few cycles rewriting memory with no effect.

> [@VerminProgrammer](#):
>
> `print updateVFD1(memory_state1, 0)`

As mentioned above - there's no need to pass parameters in here - just invoke the function directly (`updateVFD1()`). Also, your function isn't `return`ing anything, so there's no need to print the output - that's what the `None` value you're seeing in the script console is.

I would put the following into the project library, for now:

```python
def updateVFD1():
	log = system.util.getLogger("VFD Debug")
	run_state1 = system.tag.readBlocking("[default]CHW/VFD/New Instance/VFD1")[0].value
	memory_state1 = system.tag.readBlocking("[default]CHW/VFD/Runtime/CHP-1")[0].value

	log.info("Original value: " + run_state1)
	if run_state1 > memory_state1:
		system.tag.writeBlocking("[default]CHW/VFD/Runtime/CHP-1", memory_state1)
		log.info("Updated memory state value: " + memory_state1)
	else: 
		log.info("Not updated")

```

And then in your timer script, just write:

```python
whateverNameYouGaveYourProjectScriptLibrary.updateVFD1()

```

If you weren't aware of it, Ctrl + Space brings up the scripting autocomplete, and if you're on a recent enough version this will also bring up project library scripts.

---

_[View the full topic](https://forum.inductiveautomation.com/t/time-tracking-using-gateway-timer-script/94076)._
