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

2013/11/8

Barrier repair code URGENT PLEASE HELP ;'( !!!!

benskii93 benskii93

2013/11/8

#
Ok I really shouldn't have left it this late but my assignment is due in like 3 hours and I have this problem which I have just tried everything with. I am making a space-invaders remake and one added feature is a repair tool that when activated repairs all barriers. Here is the Player class code with the Repair function. public void Repair() { Actor Repair_Indicator = new Repair_Indicator(); if (gotRepair == true && Greenfoot.isKeyDown ("up")) { gotRepair = false; getWorld().removeObject(repair_indicator); Barrier.GetRepaired(); } This code calls a function in the Barrier class, here is the code for that: public static void GetRepaired() { int health = 10; } The health variable is declared at the top of the barrier class and initialized at 10, when bullets hit the barriers the health goes down, and this function should put it back up to 10, but I activate the repair tool and nothing happens, could someone help me out please?
erdelf erdelf

2013/11/8

#
at first, u are never really adding the repair indicator to the world, so there is no need to remove it, i have no really idea why u are even creating it. and change the line
int health = 10;
to
health = 10;
Busch2207 Busch2207

2013/11/8

#
You wrote: int health = 10; with this 'int' in front of it you declare a new variable which has the same name like your variable at the top. To call the variable, you declared on the top, you just have to remove the 'int' in front of the 'health'. :)
benskii93 benskii93

2013/11/8

#
The repair indicator is created randomly when I kill aliens, I need it to be able to repair the barriers. and I have tried removing the int, It still does not work :(
erdelf erdelf

2013/11/8

#
i cant really find another error, is the method repair() called in the act cycle or something`?
danpost danpost

2013/11/8

#
I believe there is a similar type error in the Repair method, in that you are creating a new Repair_Indicator that never gets a chance to be activated before you check its value. It (the Repair_Indicator created during that execution of the method) exists only up until the method is exited. You may or may not have a Repair_Indicator declared in the class; however, when giving insufficient information, it is hard to say how to fix it. Please show the code for the entire class and use the 'code' tag below the 'Post a reply' box to insert the code with. Also, explain exactly how you want the repairing to be done. All barriers at once or individually; is there more to repairing than just putting the value of 'health' back to 10; etc. The more info you supply, the easier and faster the process of resolving your issues.
You need to login to post a reply.