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

2016/6/22

Given Key

3r1kMort 3r1kMort

2016/6/22

#
I want to make an adventure game where an NPC gives the player a key after talking (think of the classic LoZ game where the magician gives you a sword). How would I code it to automatically give the player the key only after talking to the NPC? Help would be much appreciated. :)
danpost danpost

2016/6/22

#
In general (in NPC class):
if (dialogComplete && player.key == null)
{
    player.key = new Key();
    dialogComplete = false;
}
where 'dialogComplete' is a boolean field in the NPC class and 'key' is a public Key reference field in the player class. Also, 'player', in the code given, is not the class name here. It is a reference to the object representing the player. The class does not get the key -- the player instance does.
You need to login to post a reply.