Random item from Structure data type

Hi guys,
I need your help. I need to choose a random color for my objects. I use Global Variables for colors and I put them into the Structure data type.

For example, I have four white boxes (oject1, oject2, oject3 and oject4). At the beginning of the scene, I want to change their tint randomly, but I need only one color for each object.

How can I do that?

Best way I can think is to generate a random number between 1 and 4, then choose a colour based on a mapping between numbers and colours (e.g. 1=blue, 2=green, etc.).

That’s fine and the best way if the colours are in an array.

But a structure is a dictionary; a key-value pairing, and you need the key name, not it’s position/index.

If @BeF1990 needs the colours in a structure, then the following will work :


Or for an array that can be accessed in other events :

2 Likes

So I’m trying a different approach, but still have a problem.

Here you can see my new Global Variables:

and here I want to assign random color from the text object “color0”, but I don’t know how to do that:

I thought I can do this, but it doesn’t work:

Any suggestion how to solve it?

colour0 is an object, not a variable. Just use color0.String()

1 Like