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

2020/3/2

Boss with healthbar

1
2
3
footpickle footpickle

2020/3/3

#
is it the private or public things?
Yoshi21137 Yoshi21137

2020/3/3

#
I put some code into the boss class but it doesn't work. Boss Class

private BossHealth bossHealth;

public void act()
{
    if (getWorld() != null)
        {
            bossHealth.setLocation(getX(), getY());
        }
}
Yoshi21137 Yoshi21137

2020/3/3

#
The problem is in line 7
bossHealth.setLocation(getX(), getY());
footpickle footpickle

2020/3/3

#
You didn't put the -25 but I'm not sure how much difference that makes
Yoshi21137 Yoshi21137

2020/3/3

#
it doesn't make a difference because it still gives me a java.lang.NullPointerException
footpickle footpickle

2020/3/3

#
Ok... You know I'm an idiot. Come on, don't try things I suggest. They never work. :\
footpickle footpickle

2020/3/3

#
Wait, I think you need to put the Boss in the world first. Have you tried that?
Yoshi21137 Yoshi21137

2020/3/3

#
I know that doesn't work because that is what this line checks:
if (main != null)
Yoshi21137 Yoshi21137

2020/3/3

#
footpickle wrote...
Ok... You know I'm an idiot. Come on, don't try things I suggest. They never work. :\
If that is true, then don't post here because it is not helpful
footpickle footpickle

2020/3/3

#
:( I'm just trying to help
danpost danpost

2020/3/3

#
Yoshi21137 wrote...
it doesn't make a difference because it still gives me a java.lang.NullPointerException
danpost wrote...
if the health bar that is added into the world was assigned to that field
You probably have not assigned anything to your bossHealth field.
Yoshi21137 Yoshi21137

2020/3/3

#
How do I do that?
danpost danpost

2020/3/3

#
Yoshi21137 wrote...
How do I do that?
Probably the easiest way is to create a method in the Boss class to accept a BossHealth object and then assign it to the field.
footpickle footpickle

2020/3/3

#
How would one do that?
footpickle footpickle

2020/3/4

#
How would someone do that?
There are more replies on the next page.
1
2
3