Help with a tricky rule.

In my game the person kind has a property of either hostile or friendly (usually friendly). There is a type of person called an animal, and a type of animal called a lion. This lion, after examined four times becomes hostile. That whole part is perfect how it is. The problem is in my every turn rule that makes hostile people attack.

I used a basic weapon and fighting system I found in the documentation. In it there are weapons which have an amount of damage.

This is what I want to happen: Every turn that the player can see a hostile person that hostile person should attack the player with a random weapon they carry (If they aren’t dead). I’ve been experimenting with different codes and getting all sorts of errors.

This is the code I have now:

Every turn when the player can see someone and the person asked is hostile:
if the person asked is not dead, try the person asked attacking the player with a random weapon which is carried by the person asked.

Currently the code is compiling, but after I examine the lion 4 times, and get the correct messages, the lion never ends up attacking me.

Any ideas? :nerd:

“The person asked” is only meaningful during an action like “robot, go north”. That’s not what you want.

You can do this:

Every turn when the player can see someone hostile (called P):
	if P is not dead:
		try P attacking the player with a random thing which is carried by P.

This will only pick one hostile person to test every turn, though, which might give you bad results. (For example, if there’s a dead hostile person in the room, it might pick that one every turn and then fail the “if” test.)

Thank you for your suggestion. I substituted this in for the code I had, and it worked flawlessly. The only concern I have is the one you said. At the moment only one hostile person is existent at a time. If anyone thinks of another way that would work for all, tell me.

Perhaps something that checks from the person’s point of view, checking if it can see the player, etc? That way it’s processed for each person in the room? I don’t know exactly how writing this would go, any suggestions?

How about:

Every turn while the player can see someone hostile: repeat with P running through hostile people in the location of the player: if P is not dead: try P attacking the noun with a random thing which is carried by P.

EDIT: Oops, Gravel’s right.

Probably want to attack the player, and not the noun.

The new solution is flawless. Thank you.

I’ll say, it’s much easier to solve problems when you have a forum! :wink: