Announcement

Collapse
No announcement yet.

Can Scripts Using the Same Variable Names Run Simultaneously?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can Scripts Using the Same Variable Names Run Simultaneously?

    The title is pretty self explanatory, but I have created 3 countdown timers for my attic fans using scripts. The scripts are identical except for the device names, and timers. The script works fine when I run one at a time, but when all three attic fans are running, only the one started first works. The scripts use various variable names like TimeRemaining, HoursStr, etc., which are the same in all 3 scripts. I assume that the scripts are not self-contained, and therefore need to use different variable names?

  • #2
    How and where in the scripts are you declaring your variables?
    HS 3.0.0.548: 1990 Devices 1172 Events
    Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

    Comment


    • #3
      Thanks for the reply sparkman . Here's the first part of the script with the variable declarations.

      Code:
      Public Sub Main(param As Object)
      
      ' ###############################################################################################
          Dim Countdown_Status_Ref as integer = 1032     ' Device Number of Status Trigger
          Dim Countdown_Seconds_Ref as integer = 1036    ' Device Number of Counter
          Dim Timer as string = "Attic Fan Office"         ' Name of Timer to use
          Dim Run_Time_Ref as integer = 170              ' Name of Run Time Device to use
          Dim Time_Remaining_Ref as integer = 1033        ' Name of Time Remaining Virtual Dev
      ' ###############################################################################################
      
          Dim FlagOFF as integer = 0                      ' Flag Disabled or OFF
          Dim FlagON as integer = 100                     ' Flag Enabled or ON
          Dim Hours as integer = 0
          Dim HoursStr as String = ""
          Dim Minutes as integer = 0
          Dim MinutesStr as String = ""
          Dim TimeStr as String = ""
      
          Dim StartValue as integer = hs.DeviceValue(Run_Time_Ref)   ' Get initial start value
          Dim SecondsRemaining as integer = StartValue

      Comment


      • #4
        All of those variables you declare are local to that Main procedure. A separate running of this script will create its own copy of those variables. So from what is shown, that is not the problem.

        Check to see how your scripts are being started. Do you have the "Run only one copy at a time" set?

        Comment


        • #5
          Try changing “Public Sub Main” to just “Sub Main”. I never use the Public declaration in my scripts and have never experienced this issue (and I run a lot of scripts that use the same variable names).
          HS 3.0.0.548: 1990 Devices 1172 Events
          Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

          Comment


          • #6
            Another thing to do (assuming the previous suggestions do not fix the problem) is to examine the system log when the other scripts should be running. The log may tell you why.

            Comment


            • #7
              Originally posted by aa6vh View Post
              Another thing to do (assuming the previous suggestions do not fix the problem) is to examine the system log when the other scripts should be running. The log may tell you why.
              I checked that. No unusual log entries or errors.

              Comment


              • #8
                Originally posted by sparkman View Post
                Try changing “Public Sub Main” to just “Sub Main”. I never use the Public declaration in my scripts and have never experienced this issue (and I run a lot of scripts that use the same variable names).
                Thanks, that fixed it. All three are running at the same time with no issues.

                Comment

                Working...
                X