We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I keep using the shots.add function but it only works when I have an empty bracket at the end of the code, what is going on?
float randomside = 0.0;
float bulletup = 650;
int moveup = 60;
float fastdot = mouseX;
float dotcoordiant = -50;
int lastTomeCheck;
int lastTimeCheck;
int timeIntervalFlag = 6500;
int timeIntervalFlag2 = 30;
void setup() {
size (500, 720);
background (256,256,256);
strokeWeight(10);
frameRate(60);
lastTimeCheck = millis();
if(mousePressed == true){
point(fastdot, bulletup);
}
}
void draw(){
background (256,256,256);
randomside = random(450);
stroke(0,0,256);
point(mouseX,650);
bulletup = bulletup - 10;
//bulletcode
if (bulletup < 0 ){
bulletup = 650;
}
if(mousePressed == true){
for (int bulletup = 650; bulletup < 0; bulletup = bulletup-5){
bulletup = 650;
}
point(mouseX, bulletup);
}
if ( millis() > lastTimeCheck + timeIntervalFlag ) {
lastTimeCheck = millis();
moveup = 60;
println(lastTimeCheck);
}
/*if ( millis() > lastTimeCheck + timeIntervalFlag2 ) {
lastTimeCheck = millis();
bulletup = bulletup;
println(lastTimeCheck);
}
*/
stroke(256,0,0);
moveup = moveup + 10;
point(270,-50 + moveup);
point(300,-100 + moveup);
point(330,-150 + moveup);
point(360,-200 + moveup);
point(390,-250 + moveup);
point(420,-300 + moveup);
point(450,-350 + moveup);
point(500,-400 + moveup);
point(470,-450 + moveup);
point(440,-500 + moveup);
point(420,-550 + moveup);
point(270,-50 + moveup);
point(300,-100 + moveup);
point(330,-150 + moveup);
point(360,-200 + moveup);
point(390,-250 + moveup);
point(420,-300 + moveup);
point(450,-350 + moveup);
point(500,-400 + moveup);
point(470,-450 + moveup);
point(440,-500 + moveup);
point(420,-550 + moveup);
point(400,-600 + moveup);
point(380,-650 + moveup);
point(360,-700 + moveup);
point(440,-750 + moveup);
point(420,-800 + moveup);
point(400,-850 + moveup);
point(380,-900 + moveup);
point(360,-950 + moveup);
point(340,-1000 + moveup);
point(320,-1050 + moveup);
point(300,-1100 + moveup);
point(280,-1150 + moveup);
point(260,-1200 + moveup);
point(240,-1250 + moveup);
point(220,-1300 + moveup);
point(200,-1350 + moveup);
point(180,-1400 + moveup);
point(160,-1450 + moveup);
point(140,-1500 + moveup);
point(120,-1550 + moveup);
point(100,-1600 + moveup);
point(80,-1650 + moveup);
point(60,-1700 + moveup);
point(40,-1750 + moveup);
point(20,-1800 + moveup);
point(0,-1850 + moveup);
//buzzpoints
point(random(50) + random (10) + 0 ,random (10) + -1900 + moveup);
point(random(50) + random (10) + 0 ,random (10) + -1910 + moveup);
point(random(50) + random (10) + 0 ,random (10) + -1920 + moveup);
point(random(50) + random (50) + 0 ,random (10) + -1930 + moveup);
point(random(50) + random (50) + 0 ,random (10) + -1940 + moveup);
point(random(50) + random (50) + 0 ,random (10) + -1950 + moveup);
point(random(50) + random (60) + 0 ,random (10) + -1930 + moveup);
point(random(50) + random (60) + 0 ,random (10) + -1940 + moveup);
point(random(50) + random (60) + 0 ,random (10) + -1950 + moveup);
point(random(50) + random (70) + 0 ,random (10) + -1930 + moveup);
point(random(50) + random (70) + 0 ,random (10) + -1940 + moveup);
point(random(50) + random (70) + 0 ,random (10) + -1950 + moveup);
//2
point(random(50) + random (80) + 0 ,random (10) + -1960 + moveup);
point(random(50) + random (80) + 0 ,random (10) + -1970 + moveup);
point(random(50) + random (80) + 0 ,random (10) + -1980 + moveup);
point(random(50) + random (90) + 0 ,random (10) + -1990 + moveup);
point(random(50) + random (90) + 0 ,random (10) + -2000 + moveup);
point(random(50) + random (90) + 0 ,random (10) + -2010 + moveup);
point(random(50) + random (100) + 0 ,random (10) + -2020 + moveup);
point(random(50) + random (100) + 0 ,random (10) + -2030 + moveup);
point(random(50) + random (100) + 0 ,random (10) + -2040 + moveup);
//3
point(random(50) + random (110) + 0 ,random (10) + -2050 + moveup);
point(random(50) + random (110) + 0 ,random (10) + -2060 + moveup);
point(random(50) + random (110) + 0 ,random (10) + -2070 + moveup);
//4
point(random(50) + random (120) + 0 ,random (10) + -2080 + moveup);
point(random(50) + random (120) + 0 ,random (10) + -2090 + moveup);
point(random(50) + random (120) + 0 ,random (10) + -2100 + moveup);
//5
point(random(50) + random (130) + 0 ,random (10) + -2110 + moveup);
point(random(50) + random (130) + 0 ,random (10) + -2110 + moveup);
point(random(50) + random (130) + 0 ,random (10) + -2110 + moveup);
//6
point(random(50) + random (140) + 0 ,random (10) + -2120 + moveup);
point(random(50) + random (140) + 0 ,random (10) + -2130 + moveup);
point(random(50) + random (140) + 0 ,random (10) + -2140 + moveup);
//7
point(random(50) + random (150) + 0 ,random (10) + -2150 + moveup);
point(random(50) + random (150) + 0 ,random (10) + -2160 + moveup);
point(random(50) + random (150) + 0 ,random (10) + -2170 + moveup);
//8
point(random(50) + random (160) + 0 ,random (10) + -2180 + moveup);
point(random(50) + random (160) + 0 ,random (10) + -2190 + moveup);
point(random(50) + random (160) + 0 ,random (10) + -2200 + moveup);
//9
point(random(50) + random (170) + 0 ,random (10) + -2210 + moveup);
point(random(50) + random (170) + 0 ,random (10) + -2220 + moveup);
point(random(50) + random (170) + 0 ,random (10) + -2230 + moveup);
//10
point(random(50) + random (180) + 0 ,random (10) + -2240 + moveup);
point(random(50) + random (180) + 0 ,random (10) + -2250 + moveup);
point(random(50) + random (170) + 0 ,random (10) + -2260 + moveup);
//11
point(random(50) + random (190) + 0 ,random (10) + -2270 + moveup);
point(random(50) + random (190) + 0 ,random (10) + -2280 + moveup);
point(random(50) + random (190) + 0 ,random (10) + -2290 + moveup);
//12
point(random(50) + random (200) + 0 ,random (10) + -2300 + moveup);
point(random(50) + random (200) + 0 ,random (10) + -2310 + moveup);
point(random(50) + random (200) + 0 ,random (10) + -2320 + moveup);
//13
point(random(50) + random (210) + 0 ,random (10) + -2330 + moveup);
point(random(50) + random (210) + 0 ,random (10) + -2340 + moveup);
point(random(50) + random (210) + 0 ,random (10) + -2350 + moveup);
//14
point(random(50) + random (220) + 0 ,random (10) + -2360 + moveup);
point(random(50) + random (220) + 0 ,random (10) + -2370 + moveup);
point(random(50) + random (220) + 0 ,random (10) + -2380 + moveup);
//15
point(random(50) + random (230) + 0 ,random (10) + -2390 + moveup);
point(random(50) + random (230) + 0 ,random (10) + -2400 + moveup);
point(random(50) + random (230) + 0 ,random (10) + -2410 + moveup);
//16
point(random(50) + random (240) + 0 ,random (10) + -2420 + moveup);
point(random(50) + random (250) + 0 ,random (10) + -2430 + moveup);
point(random(50) + random (260) + 0 ,random (10) + -2440 + moveup);
//17
point(random(50) + random (270) + 0 ,random (10) + -2450 + moveup);
point(random(50) + random (270) + 0 ,random (10) + -2460 + moveup);
point(random(50) + random (270) + 0 ,random (10) + -2470 + moveup);
//18
point(random(50) + random (280) + 0 ,random (10) + -2480 + moveup);
point(random(50) + random (280) + 0 ,random (10) + -2490 + moveup);
point(random(50) + random (280) + 0 ,random (10) + -2500 + moveup);
}
//this is the section of code with problems
void mousePressed(){
shots.add( new Shot( mouseX, mouseY, 0, -5 ) );
shots.add( new Shot( mouseX, mouseY, -.5, -5 ) );
shots.add( new Shot( mouseX, mouseY, .5, -5 ) );
}
}
Answers
Hit ctrl-t to get Auto-Format
Then check the indentation of corresponding brackets
Guess the bracket belongs before mousePressed
The only problem with the code is that it doesn't recognise the shots arraylist and the Shot class. I suspect you have another tab for the Shot class and the syntax error is in that tab.
I do have an extra tab, but there is nothing in it.
I would remove this. At best it does nothing. At worst it'll be an infinite loop. You have a variable called bulletup but you've redefined it in the first line and that'll go out of scope when the loop finishes.
now
if ( millis() > lastTimeCheck + timeIntervalFlag ) {
isn't workingshow your entire runnable code
maybe you forgot to define lastTimeCheck=millis();