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,
});
- Raphael Sepulveda @raphaelsepulveda2022-01-16 23:40:41.893Z
Hey Steve!
You can use Type: Byte for this.
Christian Scheuer @chrscheuer2022-01-17 11:42:29.633Z
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.
Christian Scheuer @chrscheuer2022-01-17 12:47:06.069Z
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.- 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, });
Christian Scheuer @chrscheuer2022-01-17 19:04:00.194Z
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),
- In reply tochrscheuer⬆:
Raphael Sepulveda @raphaelsepulveda2022-01-17 19:56:39.287Z
Ahh, good to know!