Pages: [1]   Go Down
Author Topic: Arduino Beginner Touchshield Slide PImage Arrays Help  (Read 729 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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?
« Last Edit: June 15, 2012, 08:08:33 pm by ssj2miguelx » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49365
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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:
int i;[shadow=red,left][/shadow]
This line needs fixing, for sure.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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:
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+'
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49365
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: