Help with image that doesn't appear

So… I know it has been a while, I need some help though. If you look in the top left of the screen, the dice face isn’t appearing underneath the “Attack” text. For context I am doing some really painful stuff with arrays, colour, images, and functions.

would really appreciate help :slight_smile:

1 Like

Hmmmm…

I suspect the problem is that you’re thinking that temp dice image list is a duplicate of dice image list reference. It is not. It’s the same array – meaning the exact same variable. When you manipulate temp dice image list, you also are changing dice image list reference, too.

Am I interpreting your intentions correctly?

3 Likes

so it is sort of linking them? that seems weird

Basically, yes.

It’s the same ideas as doing this:

The two variables point to the same sprite. Changing the sprite with one of the variables will change it for the other, since they both reference the same place in memory.

Sprites, images, arrays, and other complex variables (they’re technically known as objects or instances) reference specific places in memory. If two variables point to the same place in memory, then changing one variable will affect the other.

2 Likes

Simplest solution: If you want to work with a copy of an array, then make an actual copy. Best way to do that is to create a function.

  1. Create an empty array in the function.
  2. Then, iterate through the original array, duplicate each image, and then add the duplicated image to the new array.
  3. After duplicating all of the images, have the function return the new array.

For those of you seeing this after the fact and working in JavaScript, use the slice() function instead, which can be used to duplicate an array.

let arrayCopy: Image[] = originalImages.slice(0)
1 Like

Ah ok thanks, that was just what I was thinking :+1:

2 Likes