Go Down

Topic: Arduino Beginner Touchshield Slide PImage Arrays Help (Read 865 times) previous topic - next topic

Jun 16, 2012, 02:03 am Last Edit: Jun 16, 2012, 03:08 am by ssj2miguelx Reason: 1
Hello guys,

I am having issues making this game which has a lot of small images that I would like to load to the Touchshield Slide but g++ compiler (Antipasto) is not accepting the syntax to create an PImage array. (The Board is set to Touchshield Slide)

For instance, i want to use a for loop to change the names of the files uploaded but it throws an error for :
Code: [Select]

PImage[] stonePit = new PImage[21];
PImage[] kalaPit = new PImage[49];
int i;[shadow=red,left][/shadow]
void setup (){
for (i=0; i <=TotalStone; i++)stonePit[i] = loadImage("Stonepit" + i + ".bmp");
for (i=0; i <=TotalKala; i++) kalaPit[i] = loadImage("KalaStone" +  i + ".bmp");


The error being thrown is "error: expected unqualified-id before '[' token" at both PImage[] lines at the top where I am defining my PImage array and for both of the for loops, I am getting error code  "error: 'stonePit' was not declared in this scope" and "error: invalid operands of types 'const char*' and 'const." I've been working at this for hours and I am still not getting it. Maybe i need to do it without an array, but how do I dynamically point to different objects in the game?

PaulS

Code: [Select]
PImage[] stonePit = new PImage[21];
PImage[] kalaPit = new PImage[49];

Perhaps you need to do some research on how arrays are declared in C or C++, rather than C# or Java. Your [] are in the wrong place. Trey need to follow the array name, not the array type.

Code: [Select]
int i;[shadow=red,left][/shadow]
This line needs fixing, for sure.


That makes sense, I just saw that way of initialization the pimage array on a processing website. (http://processing.org/discourse/beta/num_1192465513.html)

Here is what I've changed it to which seems to be the right way but the compiler throws this error.

Code: [Select]
PImage stonePit[] = new PImage[21];
PImage kalaPit[] = new PImage[49];

error: initializer fails to determine size of 'stonePit'
error: initializer fails to determine size of 'kalaPit'


Also, there is a second error here regarding the for-loop which throws this error below due to the way I am making a string " loadImage("Stonepit" + i + ".bmp")".
Code: [Select]
for (i=0; i <=TotalStone; i++)stonePit[i] = loadImage("Stonepit" + i + ".bmp");
for (i=0; i <=TotalKala; i++) kalaPit[i] = loadImage("KalaStone" +  i + ".bmp");

I thought this would work in the Touchshield slide unless I have to hardcode it.

Error:

error: invalid operands of types 'const char*' and 'const char [5]' to binary 'operator+'
error: invalid operands of types 'const char*' and 'const char [5]' to binary 'operator+'

PaulS

Quote
That makes sense, I just saw that way of initialization the pimage array on a processing website.

Processing is Java-based.

Typically, the new operator in C++ returns a pointer. You need to have an array of pointers, and initialize the array elements in a loop.

In C++, + is not a concatenation symbol for strings. It is an addition operator. Adding an int to a string makes no sense. sprintf() is your friend.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy