No internet connection
  1. Home
  2. How to

Template Property - What to use instead of String for user defined number

I have a script/template where I would like to define how many repetitions when pressing the key "up arrow" with a property in my template. Strings & User-Defined Enums seem to fail with numbers. What method should I use in a property to allow the user to define the number (i.e. "1", "2", "3", etc)

sf.keyboard.press({
keys: "up",
repetitions: 1,
});

  • 6 replies
  1. Hey Steve!

    You can use Type: Byte for this.

    1. I would recommend using Int32 as a more standard type for this though, since yes, in most practical aspects Byte would work as well, albeit be limited to values ranging 0..255.

      1. Int32 means a 32-bit signed integer, so, a whole number in the range of -2147483648 to 2147483647. Byte is an 8-bit unsigned integer in the range 0..255.
        There's no real good reason why we present all these options to you, the options should really just be Integer or Floating Point Number, which is why I would discourage using Byte as it just artificially limits the range of input which could cause problems down the line if you ever needed that range to widen.

        1. SSteve Bissinger @sbiss2022-01-17 18:56:36.435Z2022-01-18 23:45:29.644Z

          I've converted the property to Int32, but am still getting the error "Expected number but got String". With Int32 do use it like I would a String:

          const {
              upStrokes,
              downStrokes,
          } = event.props
          
          sf.keyboard.press({
              keys: "down",
              repetitions: downStrokes,
          });
          
          1. You would also need to re-enter the values in each preset if you haven't already, as your presets could be holding old string values.

            To force a number, even if a string was received, you could use the Number function, like so: repetitions: Number(downStrokes),

          2. In reply tochrscheuer:

            Ahh, good to know!