We are about to switch to a new forum software. Until then we have removed the registration on this forum.
So I have this silly error, I've already looked it up on this site but all I will not work, so I hope you can find my mistake. It's a programm about a spaceship and this little spaceship should shoot lasers every time you hit the mouse. The lasers are not done yet, I just want to figure out how to add objects in an array every time I click the mouse. Code :
[see below for code]
If there are questions about the code feel free to ask, thank you very much!
Answers
edit post, highlight code, press ctrl-o to format
what is i here?
[Unformatted code deleted]
i is the variable for the array length
edit post, highlight code, press ctrl-o to format
What value does it have?
in setup() there is the for loop in which I gave it the value 0, and as long as it is less than 10, it should go up by one (i++). so It counts the index array from 0, but it wont work
We can't read your code until you format it so you need to do that before we can comment further.
And this is the laziest and most worthless of bug reports
If you click the cog on the first post you can edit that, rather than reposting the same error again and again.
Highlight the code, press Ctrl-o, that's all it needs.
ok, cool. now we have line numbers so i can say things like:
line 48, what is the value of i?
no clue, I don't know how I cand add a new Object to the array every time I click the mouse, I'm a bit helpless with that topic
try adding line 47
(your code is missing the Ship class btw, we can't run it)
this is basically your current problem. the variable you use as a lopo counter is outside of the bounds when you try and use it after the loop
it is more traditional to define the index counter inside the for loop
for (int i = 0...)
, limiting its scope to the loop.line 48 just looks a bit extraneous the way it is. is it just an error? or does it need a loop around it?
your overall problem, being able to add things to your group, is better done using an ArrayList which, unlike arrays, are designed to grow and shrink when required.
https://processing.org/reference/ArrayList.html