# Cannot repeatedly call scripts with parameters

**URL:** <https://forum.inductiveautomation.com/t/cannot-repeatedly-call-scripts-with-parameters/82942>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [December 10, 2023, 9:22am UTC](https://forum.inductiveautomation.com/t/cannot-repeatedly-call-scripts-with-parameters/82942 "2023-12-10T09:22:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chen\_zhe](https://avatars.discourse-cdn.com/v4/letter/c/c0e974/32.png) [@chen\_zhe](https://forum.inductiveautomation.com/u/chen_zhe)\
**Post date:** [December 10, 2023, 9:22am UTC](https://forum.inductiveautomation.com/t/cannot-repeatedly-call-scripts-with-parameters/82942/1 "2023-12-10T09:22:14Z")

</div>

in perspective  
Cannot repeatedly call scripts with parameters, and everytime after saving the project, the global variables of the script will be reset to zero, and the output value will also be zero

 ![hhh](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/8/a8c38b2d40867db76fcd90e4439ec7e9889dc16b.jpeg)  
 ![ggg](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/2/f2faa7cf3cb274eca054613b5ec3d5da8d83ba6d.jpeg)

```auto
import time
total = 0
tempa = 0
oldtotal = 0
def calculate_downtime(start):    
    global total, tempa, start_time, end_time,oldtotal
    if start == False and tempa == 0:  
        start_time = time.time()  
        tempa = 1  
    elif start == True:
         tempa = 0   
    if tempa == 1:  
        end_time = time.time()  
        total = (end_time - start_time) + oldtotal
        return total/60
    elif tempa == 0:
         oldtotal = total
         return oldtotal/60

```

This is a script for calculating cumulative downtime, accumulating when start is 1 and stopping when start is 0

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [December 10, 2023, 12:34pm UTC](https://forum.inductiveautomation.com/t/cannot-repeatedly-call-scripts-with-parameters/82942/2 "2023-12-10T12:34:45Z")

</div>

I think you should be logging events, with a timestamp, and using those to calculate the downtime. It would be simpler and more robust.

If you don't want to do that, you need to rethink the way you store data. There's a number of discussions around here about data persistence, do a quick search to find how to do it properly.

---

<div class="post-metadata">

**Author:** ![chen\_zhe](https://avatars.discourse-cdn.com/v4/letter/c/c0e974/32.png) [@chen\_zhe](https://forum.inductiveautomation.com/u/chen_zhe)\
**Post date:** [December 10, 2023, 2:44pm UTC](https://forum.inductiveautomation.com/t/cannot-repeatedly-call-scripts-with-parameters/82942/3 "2023-12-10T14:44:29Z")

</div>

There will be multiple shutdowns every day, and the total time will be reset to zero when changing shifts at 8 am and 8 pm

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [December 10, 2023, 5:43pm UTC](https://forum.inductiveautomation.com/t/cannot-repeatedly-call-scripts-with-parameters/82942/4 "2023-12-10T17:43:54Z")

</div>

Which is handled perfectly with an event history.
