local colours = {
blue,
yellow,
red,
green
}
local chosenColour = math.random(1, #colours)
In my code I’m aiming to pick a random colour from the colours table (which I know how to do), but I want to be able to store the selected colour as a variable to be used throughout the round. The problem is, I want to store the colour to be used for only one round, and to pick a new random colour for every round, and I’m unsure how to do this. Any help? (sorry if I’m explaining this poorly, feel free to ask questions)
I’ve looked around but don’t seem to find any assistance for this.
variables are re-definded inside each while loop(round). As long as you put the variable inside the while loop it’ll only be the color for just that round. so like this
while true do
local colours = {
blue,
yellow,
red,
green
}
local chosenColour = local chosenColour = colours[math.random(1, #colours)] -- this will be different per round
end
It works! Thank you. Just a quick question so that I understand the code… why does it reset each round and how does chosenColour stay the same in the loop instead of giving me a different value each time the variable is used?