0 votes
by (220 points)
Hey all, newbie here working on Twine because Inform 7 is...just a headache. I know Twine isn't exactly the best to create an rpg in, but I've read through some tutorials and examples and already have a working skeleton within a day, so I'm feeling confident

I want to have a location (passage) where the player can explore from. Exploring can lead to treasure, a monster to fight, or a other random event. Each location has a set of monsters that can be found there.

What I'm looking for is if a player finds a monster (using an (if: (random: ) ) setup, to choose a monster from a set, and then (set:) variables such as health, strength, etc from a passage for that monster before getting to the passage with the battle mechanics.

Is this do-able without having to write out endless versions of (set:) for every every monster in the same passage?

Thanks in advance for the advice!

-ZTP

1 Answer

+1 vote
by (144k points)

opinion: I personally wouldn't use Harlowe to create what you want due to the fact that Harlowe clones the entirety of an array (or data-map) every time you change the value of one of it's elements/members, but you asked for suggestions on how to implement what you want with that story format so the following is one possible method.

(set: $possible to (array: "Orc", "Kobold"))
(set: _selected to (shuffled: ...$possible)'s 1st)
(set: $monster to (datamap:))

|workarea)[]

<!-- Initialise the monster. -->
(replace: ?workarea)[(display: _selected)]

<!-- Execute the combat code. -->
(replace: ?workarea)[(display: "Combat")]

Monster: (print: $monster's name)
HP: (print: $monster's HP)

The above example does the following:

1. Uses an array to store the names of the Passages that define each Monster, then randomly selects on of those Passages.

2. Uses a known variable (eg. $monster) which will eventually contain the META data for the selected monster.

3. Uses a hidden named hook to suppress all visual output generated by the selected monster's passage.

4. Uses a (display:) macro to execute the META definition within the selected monster's passage.

5. Uses a (display:) macro to execute the generic combat related code.

6. Displays some information about the selected monster.

The following is an example of the Orc Passage, it modifies the $monster variable to contain the META data about that monster. The Kobold Passage would look similar but with different values.

(set: $monster to (dm:
	"name", "Orc",
	"HP", 100,
	"AC", 5
))

 The following is an example of the Combat Passage, which would contain all the code related to combat. In this particular example all it does is reduce the HP of the selected monster by 10.

(set: $monster's HP to $monster's HP - 10)

 

by (220 points)
@greyelf

Okay, that makes sense to me now. I was having trouble understanding the documentation for arrays in the manual without an example. I'll give this a crack and see how it goes.

P.S. I'm using Harlowe because I'm coming from Inform 7, and the syntax/logic is a lot closer to what I'm used to than the others.
Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...