Well, this is a bit of an odd bug, but thanks to the magic of comments I've been able to track down the problem. It happens when I do the following line of code:
However, it doesn't happen all the time. If I do this in the Spike class, all is fine. Here is the reference in the Spike class:
But if I use the exact same setVolume line in the Stats class (which would make it part of the damagePlayer() method, so much nicer for me :D) I get a nullPointer exception. Here is the reference in the Stats class:
What could be the problem, as they are both actors in the world.
injury.setVolume(volumeselect.volumeLevel);
Room room = (Room)getWorld(); VolumeSelect volumeselect = room.volumeselect; GreenfootSound injury = new GreenfootSound("Injury.wav");
Room room = (Room)getWorld(); VolumeSelect volumeselect = room.volumeselect; GreenfootSound injury = new GreenfootSound("Injury.wav");