#Seeking help to expand an array of images.

6 messages · Page 1 of 1 (latest)

digital yew
#

Hello everyone! For my game art program, I have to complete these small visual array exercises and I'm stuck on this specific part. I basically have created and filled the necessary arrays, but when i tried to append my arrChoices with my arrImages, the arrChoices stays empty. Hopefully someone can point out what I'm missing here. ```java
PImage[] arrImgs;
PImage[] arrChoices;

//Executed ONCE, at startup. Setup window size, framerate, etc.:
void setup()
{
size(500,500);
fillImgArray();
}

void fillImgArray()
{
arrChoices= new PImage[0];
arrImgs = new PImage[3];
arrImgs[0] = loadImage("Asterix.png");
arrImgs[1] = loadImage("Aya.png");
arrImgs[2] = loadImage("Cat.png");
}

//Execution LOOP (60 times per second by default):
void draw()
{
//printArray(arrImgs);

for ( int i = 0; i<arrChoices.length; i++ )
{
image(arrChoices[i],10+i*arrChoices[i].width,height/2);
}
}

//Executed ONLY (but each time) mouse is pressed:
void mousePressed()
{

}

//Executed ONLY (but each time) a key is pressed:
void keyPressed()
{
if ( key == 1 )
{
arrChoices=(PImage[])append( arrChoices,arrImgs[0]);
}

if ( key == 2 )
{
arrChoices=(PImage[])append(arrChoices,arrImgs[1]);
}

if ( key == 3 )
{
arrChoices=(PImage[])append(arrChoices,arrImgs[2]);
}
}```

shadow stream
#

No way, this is Processing! Give me a moment to read all this and I'll be happy to help!

shadow stream
digital yew
shadow stream
# digital yew Hey!! This totally fixed it! crazy how it can be the small things. Thank you so ...

Happy to help! wolfcheer
It is important to know why this fixed it, though. The single quotes around each number mean that it's a character and not a number. In Java (which Processing is based on) characters can also be represented by integers, for example 'A' is 65. Digits can also be characters. I think '1' is about 49 or so. The exact specification is called Unicode, and each character has its own number to it. By adding the quotes around the numbers, you made sure to use the character '1' and not the character who's Unicode id is 1, which isn't a useful character here.

digital yew