I‘ve been intending to do this for a while now, but never got very far…
Anyway, what this will hopefully become is a compact description of Processings Java syntax.
There are many ways to find the correct syntax for specific situations, but i never found anything that describes the possible syntax alternatives for different situations, or makes it clear in less than ~100 words.
So this is my attempt at describing the syntax for beginners (who probably won‘t need to read 3 pages of text full of complex information for the time being, since that can easily take away the fun in programming for many).
This is just an attempt for now, since i don‘t know how often i can edit this post, and i hope for your help and suggestions .
This will probably take a while to complete, so don‘t expect too much to be covered for now
Hope this will help some newcomers to understand the structure of coding easier
Anyway, let‘s start :
The first thing to cover should be the syntax for declaring and defining variables :
//Declaring variables (creating variables)
ClassName variableName;
ClassName[] variableName;
ClassName variableName = new ClassName(variable...); // or new ClassName();
ClassName[] variableName = new ClassName[arrayLength];
//Defining variables (setting variables)
ClassName variableName = variable;
ClassName[] variableName = variableArray;
•ClassName is the class of the variable.
•variableName is the name of the variable you want to declare.
•variable stands for another variable of the same class that has already been declared.
•variable… means, that it is possible for multiple variable s to be used, or not to include one (leave empty, like ()). They have to be seperated by a comma and can be of different classes (although the class depends on the class required in the class initialization method and they have to be in the correct order)
•arrayLength has to be an Integer value (0,1,2).
•aariableArray stands for an already declared array of the same Class.
Example :
Ball ball;
Ball[] balls;
Ball ball = new Ball(100,30); // Where 100,30 could be the coordinates of the ball.
Ball[] balls = new Ball(); // This will create 20 variables of the class Ball.
// They have been declared like in the first line of the code above and therefore have no value attached.
// Therefore you‘ll have to define them afterwards.
// They don‘t have to be declared again.
//To define an already declared variable, you can use the same code as f0r declaring variables without including the first ClassName before the variableName
Ball ball = redBall;
Ball[] balls = redBalls; // redBalls is an array of class Ball
Next, we have to talk about declaring and calling methods :
//Declaring methods (creating methods)
Type methodName (variable...) { // if nothing should be returned, use ‚void‘
//MethodBody
return (Type) variableName; //not used if Type is ‚void‘
}
//Calling methods
ClassName.methodName(); // no return variable, since ‚void‘ has been used in the declaration
ClassName variableName = ClassName.methodName(); // returns a variable of class Type, since it used ‚ClassName‘ in it‘s declaration
•Type is the class of the variable the method will return (‚void‘ if no variable should be returned).
•methodName is the name with which the method will be called.
•MethodBody is the code that is executed when this method is called.
void printHello () {
println(„Hello“);
}
Ball getRedBall () {
return redBall;
}
void printMyText (String myText) {
println(myText);
}
Ball getRedBall (Int index) {
return redBalls[index]; //redBalls is an array of the class Ball
}
Methods are always part of a class and have to be called referencing an object or a class :
Ball.setPosition(0,0); // ‚void‘ is used in the declaration to not return a variable
Float thirdRedBallPosX = (Float) ( (Ball) ( (ManyBalls) manyBalls).getRedBall(3)).getPositionX(); // the Type of the method is Float in this case
//sorry for the mess with different classes, but i just couldn‘t come up with a better way to use the above declared method...
println(„Hello“);
// This method is also referencing a class/variable.
//To be precise, it is referencing ‚this‘, which is just implied, so you don‘t need to write it.
//In this case, this would be the PApplet (basically the main class)
I‘ll just post this for now and wait for some reactions