Welcome Forums General Here Is: How To Let The Game Know That All Monsters Are Defeated

  • This topic has 2 replies, 2 voices, and was last updated 7 months ago by Marby. This post has been viewed 146 times
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #31667
    Marby
    Moderator

    Lets say you would like to make a game, where the hero has to defeat all of the monsters in the current level. I often spotted games with exactly such a situation. However, in the games I played so far, the person in need does not know, that the hero REALLY defeated all of the monsters. That way, you can just avoid the monsters and talk to that person in order to proceed. That’s for sure not intended by the game creator!

    But how can we let a specific person know, whether all the monsters are gone or not?
    I will demonstrate this with the following little testing game:
    We will have the hero, a knight and three dragons of different colors. When the game starts, the dragons shouldn’t be there for now. First, the player has to speak to the knight. The knight will test the heroes stength and wants him to defeat the three dragons. After talking to the knight the first time, the three dragons appears and are attacking the hero. If the hero talks to the knight and has not defeated all of the dragons, the knight should be aware of this. If all the dragons have been killed, the knight will praise the hero.

    To implement this, place the knight, the dragons, an invisible switch and the hero on the first level. It makes a lot of sense to name each of these actors (except the hero, who cannot be named):
    – Name the knight “Knight”,
    – the red dragon “RedDragon”,
    – the blue dragon “BlueDragon”,
    – the black dragon “BlackDragon”,
    – and the invisible switch “InitSwitch”

    With the InitSwitch we would like to make the dragon vanish right at the beginning of the game. In order to do so, click on the InitSwitch and then choose the button “When touched…” you can see in the picture above.

    You can enter commands here, which are called “screenplay” in RPG Playground. Enter the following screenplay:

    It’s important to place the hero on the InitSwitch, before you start the game:

    When the game starts, the hero will activate the InitSwitch immediately and the screenplay will be executed.
    The first three lines of the screenplay deactivates the three dragons in order to make them disappear. The last line disables the InitSwitch. That last line prevents the hero from activating the switch multiple times and does not let the dragons disappear again.

    Now lets create our knight. First you’ve to select him, as the previous picture shows. Scroll a little down to view the “Health and Death” property section.

    Select “neutral” as the “Alignment”. In RPG Playground good fights against evil and the other way round. We want the knight to be neutral. He neither should fight the hero, nor the dragons and also should not get attacked by the dragons.

    After this is done scroll a little bit up and click on the “When touched…” button of the knight, to enter the screenplay:

    This screenplay uses a token. With tokens you can let the game remember things. You can name them as you wish, but it should be a name, you can easily remember. In this example I named our token “Talked to the Knight”. Token names always have to be enclosed in quotation marks. It is very important to have a closer look at the uppercase and lowercase letters. Be aware, that “Talked to the Knight”, “TALKED TO THE KNIGHT” or “talked to the knight” are three different tokens. Therefore you always must write a token name exactly as you wrote it the first time.

    The first line of the screenplay here just checks, if the token “Talked to the Knight” exists. If you start a game the hero does not possesses any token. The lines before the first else-statement belong together and will be executed, if the hero does not possesses the token. To make the lines belong to that if statement, we have to them indent each by four spaces.

    This screenplay makes the Knight first to tell the hero, that he has to defeat all of the dragons. The next three lines after that, makes the three dragons appear again. The last line before the first else-statement makes the token “Talked to the Knight” available.

    The lines after the first else-statement will be executed, if the condition of the if-statement before is false. Therefore, these lines will be executed, if the token “Talked to the Knight” is available. And this is the case right after the hero talked to the knight once.

    The statements at the end of this screenplay are another three if-blocks. The first if-statement checks, whether the BlueDragon is active. If it’s active is has not been slayed. In that case we let the knight say that the task is not done yet. But if the BlueDragon has been killed, we still do not know if the other dragons are killed or not. To check this, we will need the next else-statement afterwards. Next, we check the RedDragon and do the same thing as before. If the RedDragon also is dead, then the last dragon alive could be BlackDragon. So, we do the same check again with BlackDragon. Only if also BlackDragon is death we know, that the hero has done his task.

    As a disadvantage of this approach, we not only have to nest a lot of if-statements. We also need to repeat the same “Knight says”-line over and over. To improve this, we could count the dragons, which have been slayed. To do so, we need to select each of the dragons and enter some screenplay. Let’s start with the RedDragon:

    In the properties scroll a little down to the “Health and Death” section. There you’ll find the “Actions…”-button. The screenplay for this button will be executed, whenever RedDragon gets hit by a weapon. We will enter some screenplay here:

    We want to count a dragon only, if it’s death. Therefore, we need to check, whether this is the case. If the health of RedDragon is 0 the dragon is dead. The second line of this screenplay increases a number variable named “Slayed Dragons” by 1. Similar to tokens, number variables enables you to store information. The first time you use a number variable it always is 0. If RedDragon is death the number of variable “Slayed Dragon” will be increased by 1. If you also use this screenplay for the other two dragons, “Slayed Dragon” will be 3, if all our dragons have been slayed. Be aware you must use the correct health values:
    For BlueDragon you have to use:
    if BlueDragon health value = 0
    …and for BlackDragon you should use:
    if BlackDragon health value = 0

    The next and last thing we have to do is to modify the knights screenplay:

    It’s similar like the if-statements we used in order to check every single dragon. But now we just have to check “Slayed Dragons” for 3. If our number variable “Slayed Dragons” contains 3, all the dragons are death. If not, the hero has got some work left.

    Have fun while trying this!

    #32172
    deWiTTERS
    Keymaster

    One of the move extensive posts I saw here on the platform! Thanks for sharing πŸ™‚

    #32174
    Marby
    Moderator

    I’m happy you like it! πŸ™‚
    Hopefully, this will help users, who’re not this familiar with programming yet.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.