Hi! I’m working on a problem that will save me giant chunks of code if someone has the answer to this. I’m basically creating a fighting system where monsters have a series of random attacks. At this point, I’m hard-coding in each monster’s actions, because I7 doesn’t seem to like assigning values to a sub-class. For example, ‘Monster’ is a kind of person. Instead of saying, now the XXX monster is doing YYY, how can I get I7 to understand that ANY monster could be doing YYY, if they were part of that specific monster class? For a quick and dirty example, in a DnD type scenario, every kobold attacks with a sword, where every golem attacks with a stone fist, etc. But how could I have an earth golem, a stone golem, and a wood golem throw the same attack without hard-coding it specifically for each?
And, if someone tells me to use a table, then… that’s another hurdle I haven’t been able to climb just yet.
I’m not completely sure if I understand what you are looking for…but would something like the following do the trick?
A monster is a kind of person.
A kobold is a monster.
A golem is a kind of monster.
An earth golem is a golem.
A stone golem is a golem.
A wood golem is a golem.
Forest is a room. The description of forest is "You are in the forest surrounded by trees."
A stone golem is in the forest.
An earth golem is in the forest.
A wood golem is in the forest.
A kobold is in the forest.
Every turn:
repeat with creature running through visible monsters:
if creature is a golem:
say "[the creature] attacks with his fist.";
if creature is the kobold:
say "[the creature] attacks with his sword."
That’s close to the path I went down, but couldn’t make it work. Here’s the error I always bump into whenever I try to assign a variable to “a monster” vs. “stone golem”, specifically:
A monster is a kind of person.
Stone golem is a kind of monster.
A monster can be peaceful. A monster can be attacking.
If the location of the player is the location of a monster,
Now a monster is attacking.
(This is a drastic simplification – that code might even parser out, but it won’t when it gets into more complexity.)
This is the report produced by Inform 7 (build 6G60) on its most recent run through:
I read ‘a monster’ where I was expecting to find a (single) specific example of ‘a monster’.
This was what I found out:
monster = a description of monsters
That doesn’t work. If I said, ‘Now a stone golem is attacking’, that works fine. Problem is, I can’t see where the error in my logic is in relation to how the library handles classes of things – so this is an unsolvable problem for me
Instead of “If the location of the player is the location of a monster,” you can write “If a monster is in the location.” (Or “the location of the player,” but “the location” is an abbreviation of that.) Inform doesn’t know how to calculate “the location of a monster” because there are lots of different monsters.
Also you won’t be able to say “a monster is attacking” for similar reasons. You probably want “Every monster in the location is attacking.”
Every turn:
repeat with x running through monsters:
If the location of x is the location of the player:
Now x is aggressive.
Forest is a room.[/code]
Try this code works for me. What you needed to do was bring it down away from kinds, because it would try to affect every monster that away. So instead I made it X which was specific enough for the parser. Doing this actually helped me as I am working on a hunting extension. Tell me if it works for you.
Actually, as I was adding all the layers onto the variable ‘x’, I had to TAB and space over to the exact placement beneath the line above it. This makes me think using the ‘repeat with x’ loop makes I7 more strict.
You just gave me the answer, though. I was looking for a way of making an I7 variable loop and spawning creatures with it.
Awesome! The variable loop just saved me about… 5 pages or so of code. And that would have compounded
I’ll be using this system for a few different games I have ideas for, so I’m trying to develop something that has a lot of variability and fun, and that’s easy to tweak with variable difficulty levels. The problems I’m trying to solve involve a bunch of the similar monsters cluttering up the room. I want to make sure this system NEVER has the “What do you want to attack, the X, the X, or the X?” disambiguation bug. I hate that.
That’s why I created a turned based menu based combat system similar to ones seen in the old gameboy RPGs, and the Final Fantasy series. When combat starts it brought up a menu that the player could choose what to do.
How complex are you going to make it? Will there be powers and such? Are you just designing the system or is there a game you have in mind that is going to use it?
That would work beautifully, if there wasn’t random numbers and other variables involved within the loop. I’ll try any suggestion, though – I’m trying to hold a lot of varying states together, and the more elegant the code, the better.
Is there a reason not to use loops – do they slow the game down?
I’m trying to make it complicated enough that no two games will turn out exactly the same when the fighting starts. It’s not a turn based system – I’m going for something of an interactive bar fight, where lots of different things can happen, and happen at once, and found objects can be weapons. I don’t want to go too deeply into it, as it is for a specific game But, once I get the combat system I really like, I plan on using it for multiple stories.
I’m a huge fan of the old gameboy Final Fantasies, though. I loved the monster power ups, and the stories were pretty good.
Thanks, zarf. That’s good info to know. My next step is to use looping in conjunction with tables – my conversation system is just as rickety and hard coded for each character, with lots of wasted code. I’ve seen this done, but I didn’t understand looping in I7 enough to replicate it. This is getting more fun, now.