Apr 14, 2020 07:50 AM
I’m pretty new to JS, but trying to learning all the time.
Some of the first code I wrote in the scripting blog has gotten supper hard to update, so thought to experiment to write small modules to keep divide up the code.
However it seems I can’t put buttons into functions?
let test = function () {
let firstClick = await input.buttonsAsync(
'What do you want to do?',
[
{label: 'Check todays rate', value: 'today', variant: 'danger'},
{label: 'Convert currency', value: 'convert', variant: 'primary'}
]
)
}
this gives me an error saying ‘SyntaxError: await is only valid in async function’
does theis mean my button can only be used in the global scope?
Apr 14, 2020 10:50 AM
You can put buttons in functions. You just need to make the function an async function and await it when you call it.
let test = async function () {
let firstClick = await input.buttonsAsync( ...
}
await test();
May 08, 2020 07:02 AM
Sorry for the late reply, but didn’t completely understand it until I dug a bit deeper in JS and Async Await functions. Now it makes perfect sense.
Oct 05, 2020 06:39 AM
THANK YOU FOR THIS :slightly_smiling_face: I was pulling my hair out and now have it working!
Mar 17, 2023 03:28 PM
Hey All. Not sure if anyone has run into this, but it seems like use of 'variant' and 'varient' throwing inconsistent errors in my code. For example:
This works: