This site requires JavaScript, please enable it in your browser!
Greenfoot back
BananaJoe
BananaJoe wrote ...

2017/11/19

variable won`t get transfered to other class

1
2
danpost danpost

2017/11/19

#
It might be best to use just one Bin object. Keep a reference to it in the world and have the world control it. It can add it when 'dragged' is null and the mouse is moved over a cannon (at the cannon's location) and remove it when the mouse is moved off the cannon. The Bin would only need to remove the cannon at its location if clicked on. This would also avoid multiple images for the Bin object.
BananaJoe BananaJoe

2017/11/20

#
Ok, I`ll try that out, but I never worked from the world, I need some time. I´ll give feedback on how it went tomorow! :) *edited But I still have a question, how can I check only for a "newspawned" (an actor just created ) to ignore the already available. Here`s an example for clarification: I have a boat and want to check if it`s still in the port, when yes a bulb is red. When it`s out I change the status to "isOut" and a lightbulb is turning green. Now a new boat from the same class is added but I still have the old "isOut" and the lightbulb stays green(the other boat is still in the world but simply not in the port). How can I set the bulb to only the newest boat? (You can`t have more than one boat in the port) *edited edited Got a solution :)
BananaJoe BananaJoe

2017/11/20

#
I found a solution. The problem was that the bin always asked the first cannon and that couldn`t change the variable after it was set. So one last question :) At the start you told me things I could do better danpost, what do you mean with:
danpost wrote...
use of fields where variables are sufficient
what fields? I "learned"(Didnt realy spoke about that in class) to declare the in the public class and to set them in the methods. anyway I realy thank you guys for the help! Keep up the great work!
danpost danpost

2017/11/20

#
BananaJoe wrote...
Iwhat do you mean with:
danpost wrote...
use of fields where variables are sufficient
what fields?
In the originally given codes of the Bin and Cannon classes, your fields (in both) were located on lines 4 through 9. When I had first gave a revision of the Cannon class, it had only one field on line 5. When re-worked, it was made a class field instead of an instance field. All the other that you originally had were either removed entirely or changed to local variables within one of the methods. There was no need to retain their values across act steps. Looking back, I see only the 'mx' and 'my' variables on lines 34 and 35. Once you check the position of the mouse, those coordinate values that were checked beome obsolete. They are not needed on any future act step; so they are fine as local variables.
BananaJoe BananaJoe

2017/11/21

#
Thank you!
You need to login to post a reply.
1
2