As far as I’m concerned, you can simply create/initialize variables (any type of them, whether they’re boolean, integer, or decimal) inside a function; they are called local variables. And, as the name implies, they’re local, they can only be accessed through the function.

Sure, the program won’t break down if you decide to use the local variable outside of the function, however, in reality, you just made 2 variables of the same name.
Button Local Variables
If you want a function to spawn a sprite, I’d use a local variable (variables that can only be accessed in a specific function), and assign a sprite for the variable, for example: if I wanted to spawn a button at a random location every time I pressed spacebar, I would’ve wrote this function down here.

Here’s the code:

