Hopefully I’ve posted this in the right place but sorry if not.
I’m trying to do two things that I’m having trouble with and wondered if anyone can offer advice or point me in the right direction of help? Those things are:
Make hostile characters that attack the player on sight, and not only one per turn in a room.
Have it so that characters can be made hostile by attacking them (or similar).
I’ve mainly used sections from the Lanista 2 example in §7.5 and I tried using code from this post (from the intfiction forum) but seem to get errors with when I copy and paste the code in these forum posts directly.
Currently, I have:
A person can be hostile or friendly. A person is usually friendly.
Every turn while the player can see a hostile person:
repeat running through hostile people in a location:
if the person is not dead;
try the person attacking the player with a random weapon which is carried by the person;
Just to note, ‘dead’ and ‘weapon’ have been defined so hopefully they should be fine. Dead is:
A person can be alive or dead. A person is usually alive. A person with less than 1 current hit points is dead. [hit points from Lanista example]
and a weapon is:
A weapon is a kind of thing. A weapon has a number called the maximum damage. The maximum damage of a weapon is usually 4.
I think this is pretty straightforward! Your every turn rule should look something like this:
Repeat with aggressor running through people in the location:
If aggressor is hostile:
try the aggressor attacking the player with a random weapon which is carried by the aggressor.
This is close to what you have, but you need to use a more specific label – here, “aggressor” – than just “a person” in these kinds of rules, because otherwise Inform isn’t going to be sure which person you’re talking about (it’s of course clear from context, but Inform is still a programming language despite its natural language syntax, so you need to spell this stuff out!)
Then to flag people as hostile, in your main attacking it with rule (in the Lanista example, it’s the standard attacking it with a weapon rule) just add this:
If the noun is not the player:
now the noun is hostile;
(You need the conditional because otherwise the player will get hostile after being attacked by monsters and then start attacking themselves).
I was surprised this compiles and it took some effort to see why it did. The various statements about rooms and things making up the world that are outside of rules or to-phrases and aren’t preceded by now that specify the world are called “assertions”. They’re not, say “specifications”, because none of them alone is necessarily the final word on a subject. You offer the compiler a logic puzzle and it makes a series of inferences to build a world consistent with what you said. If it can’t because there’s a flat-out contradiction, it gives an error.
Anyway, A person with less than 1 current hit points is dead. says that it’s true of the world that among people with less than 1 current hit point, at least one of them is dead. Since there isn’t anyone with less than 1 current hit point, it has no effect. What you want is something like:
Definition: a person (called the combatant) is alive rather than dead if the current hit points of the combatant > 0.
The biggest other issue is that attacking is an action applying to one thing. You need to make a new action applying to two things and remove the old meaning of the “attack” command and replace it.
Those bits are:
Attacking it with is an action applying to one thing and one carried thing.
understand the command "attack" as something new.
understand "attack [thing] with [something preferably held]" as attacking it with.
Thanks so much for such swift and kind help. It’s great to see there’s such an active and helpful community on here.
Ah, I knew I was on the right tracks but these solutions worked perfectly - and your explanations really helped me understand where I was going wrong so thanks for taking the time to explain that. Thanks also for links to the appropriate guides.
Hopefully these answers might help people in the future with these kind of challenge.