That's the error I'm getting with this code and I don't understand why...
This is just a test code for the exact same problem that I'm facing in another project I'm working on. I mean, I declared an array of type G and now simply want to append objects of the same type to it. So why isn't that working?
Forgive the 600+ lines of code, but this thing is working perfectly in Java mode but isn't doing anything in Javascript mode and I fail to understand why!
UPDATE: Thanks to antony74, I know the bug and have corrected the code.
int MODE;
MenuText back;
/* @pjs font="Arial.ttf"; */
PFont titleF;
PFont menuItemF;
String[] menuItemsNames={"START","INSTRUCTIONS","CREDITS","EXIT"}; //Creates the array that will be passed to the Menu class for forming individual MenuText objects.
text("Welcome to Pong, a 2 Player, 2 Dimensional Tabble-Tennis Game",width/2-textWidth("Welcome to Pong, a 2 Player, 2 Dimensional Tabble-Tennis Game")/2,height/2-38);
text("Press W and S to control the Left Paddle",width/2-textWidth("Press W and S to control the Left Paddle")/2,height/2-10);
text("Press UP and DOWN to control the Right Paddle",width/2-textWidth("Press UP and DOWN to control the Right Paddle")/2,height/2+18);
text("Winner decided when one player amasses 10 points",width/2-textWidth("Winner decided when one player amasses 10 points")/2,height/2+46);
menuItems=new MenuText[menuItemsNames.length]; //Initializes the MenuText objects depending on the array passed to it. This makes the menu system very flexible.
void passTo(float mX,float mY){ //This accepts the X,Y mouse coords when the mouse is clicked and passes it to the relevant MenuText object to check if the click occurs on that object.
for(int i=0;i<menuItems.length;i++){
menuItems[i].mClicked(mX,mY);
}
}
void passTo(int item){
menuItems[item].unClick();
}
int whichItem(){ //Checks each time if the clicked state of any MenuText object is true. If it is, returns the array position of the relevant object.
for(int i=0;i<menuItems.length;i++){
if(menuItems[i].getClicked()){
return i;
}
}
return menuItems.length;
}
}
//MenuText holds the attributes and methods relating to each single item on the menu. Thus each item is treated as a separate object.
//Each MenuText object comprises mainly of a foreground text and a background object.
class MenuText{
String menuItem;
PFont menuFont;
float itemX;
float itemY;
float itemSize;
color itemColor;
color backColor;
color pressedColor;
color pressedBack;
color presentItem;
color presentBack;
float tWidth;
boolean clicked=false; //This vairable is used to check the clicked state of the menu item. If the mouse is clicked over the menu item, this variable becomes true.
So, I'm very new at this and this is the first thing I made, a Pong clone. Simple two-player Pong.
Have a look and see if it can be improved or anything fixed.
I'll also include the code if anyone wants a look.
UPDATE!
Managed to solve the issues with Javascript thanks to anotny74