• Categories
    • Recent
    • Tags
    • Popular
    • Register
    • Login

    Passing Variables to Scripts

    Scheduled Pinned Locked Moved Developers Zone
    4 Posts 3 Posters 2.6k Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • imediaI Offline
      imedia
      last edited by

      @jkandasa,

      Is it possible to pass variables to a script? I have written a script and I would like to pass a delay time variable depending on what triggers it. Is this possible? I think it is be means of bindings but doesn't seem to work.

      I put { delaySeconds: 10 } as the script bindings on a Operation that executes the script, on the other end I do myImports.delaySeconds but the variable seems to be null.

      Can you provide an example of doing this if it is possible?

      Thanks,

      1 Reply Last reply Reply Quote 0
      • imediaI Offline
        imedia
        last edited by

        I think I figured it out...

        I thought the variables were passed as part of the myImports object, but they need to be imported using mcApi.variable().get("delaySeconds"); instead.

        jkandasaJ 1 Reply Last reply Reply Quote 0
        • jkandasaJ Offline
          jkandasa @imedia
          last edited by

          @imedia Script bindings are variables are completely different.

          Variables - You can update in single place and refer on multiple locations. If you want to change, change it on one place. We have to add it on Utilities >> Variables repository
          You can call this as you mentioned,
          JavaScript

          myVar = mcApi.variable().get("my-variable");
          myVar.value; // Value 
          myVar.value2; // Value 2
          myVar.value3; // Value 3
          

          Script bindings- is unique for each script(from caller). You have to pass script bindings as JSON key, value. You can retrieve it as is, simply check delaySeconds, do not add anything in front like myImports.

          1 Reply Last reply Reply Quote 0
          • T Offline
            thickglass
            last edited by

            I would use object oriented style since it's more structured and better for accessing instances with

            1 Reply Last reply Reply Quote 0
            • First post
              Last post

            0

            Online

            587

            Users

            529

            Topics

            3.4k

            Posts
            Copyright © 2015-2025 MyController.org | Contributors | Localization