Selecting a random creature

I’m working on geting Inform to select a random monster in a specific room, then set him a property. The creature changes every turn while the player is safe. And when battle begins the creature is supposed to move to the battle location and it’s health is supposed to be displayed on the status line Here is some of my code:

[code]A monster is a kind of person. A wolf is a kind of monster. A forest wolf is a wolf. Bear is a kind of monster. A brown bear is a bear. 10 brown bears are in the creature vault. 5 forest wolves are in the creature vault.

A monster has a number called current hit points. A monster has a number called max hit points. The current hit points of the wolf is 10. The max hit points of the wolf is 10.

The current hit points of the brown bear is 20. The max hit points of the brown bear is 20.

A region has a thing called first default monster. A region has a thing called second default monster.

When attacked begins:
now the first default monster of the map region of the location is in the forest battle.

When attacked begins:
now the second default monster of the map region of the location is in the forest battle.

Every turn:
if the player is safe:
let X be a random person in the creature vault;
now X is the first default monster of the map region of the location;
let Y be a random person in the creature vault;
now Y is the second default monster of the map region of the location.

Table of Fancy Status
left central right
" [first default monster of the map region of the location]: [current hit points of the first default monster of the map region of the location]/[max hit points of the first default monster of the map region of the location]" “[current hit points of the player]/[max hit points of the player]” “”
" [second default monster of the map region of the location]: [current hit points of the second default monster of the map region of the location]/[max hit points of the second default monster of the map region of the location]" – “”

Rule for constructing the status line:
if the player is battled:
fill status bar with Table of Fancy Status.[/code]

I’m not sure if this is the problem area I’m just guessing. The problem that comes up is instead of displaying the monster and it hit points it say “Yourself: 10/10” and I don’t know why.

Just a guess: when the fight begins, you move the player to a room called the forest battle, right? But your “every turn” rule has set default monsters for the region in which the player was before you moved her to the forest battle room. Could this be the cause of the problem?

(By the way, if you are making a combat heavy game, you might want to check out my combat extension Inform ATTACK. Even if you do not want to use it, either the ideas or the code could serve as inspiration. If you’d like to see it in action, check out my game Kerkerkruip.)

The default object of the thing kind is yourself (also the deafult PC). So, the above code sets the first and second defulat monster to yourself.

Here X is first set to a monster from the creature vault, but then it’s immediately replaced with the first default monster, i.e. yourself (and the same goes for Y). You want:

Every turn: if the player is safe: let X be a random person in the creature vault; now the first default monster of the map region of the location is X; let Y be a random person in the creature vault; now the second default monster of the map region of the location is Y.
or simply

Every turn: now the first default monster of the map region of the location is a random person in the creature vault; now the second default monster of the map region of the location is a random person in the creature vault.

EDIT: Only, you probably also want some code to make sure that the first default monster is not identical to the second. I suppose the code above could happen to choose the choose the same random person for both default monsters.

Always advertising :unamused: I’ve actually played both your game and checked out your extension. It inspired me to make a large combat heavy game. But I’m not using it for my game since I wanted to try the combat system implemented in Final Fantasy games, I thought that It would be ideal for IF.

Ok using Felix’s second idea but adding a if player is safe has now resulted in a new error I don’t understand.

[** Programming error: Tried to find the “parent” of nothing **]

[** Programming error: Tried to find the “parent” of nothing **]

Could someone explain this? Also this problem arises when battle begins:

P15 - Can’t move nothing

Most problems are detected when Inform translates the source text, but this is one of the exceptions, a “run-time problem” which emerges only during play.

This problem occurs if a phrase tries to move something which does not exist.

The most likely way for this to occur is if a plausible name has been given to what is, most of the time, indeed a genuine thing - but not always. For instance, if we say let the heroine be the tallest woman in the Amphitheatre, supposing that we have defined tall and made such a place, then we might expect that move the heroine to the Arena would always work. In fact it would fail if there were no women in the Amphitheatre at the time we tried to set heroine, and this is the problem message which would appear.

Well, it seems as if, for some reason, your default monster variables are empty (they are “nothing”), and you have some code that tries to find out what the default monster is in, on, part of, carried by, etc. (that thing would be its “parent”), which isn’t possible as long as there is nothing that is the default monster in the first place.

Problem solved I deleted some of my code and it is now working, though I’m going to have to have to find a way to replace the code :mrgreen:

This is one of the dodgier things about I7. This will create one wolf called forest wolf, off stage, and a single thing called “5 forest wolves” in the creature vault.

If you say “a forest wolf is a kind of wolf” it does work as you mean it, and I7 even figured out that wolves is the plural of wolf.