0 votes
by (180 points)
<<for $sale = 0; $sale < $animal.length; $sale++>>\
<<set $pet = $animal[$sale]>>
<<print $pet.name>>
<<print $pet.Description>>
<<print $pet.Price>>
<<if $pcgold >= $pet.Price>>Do you wish to purchase?
<<else>>
You do not have enough to purchase it
<</if>>
<</for>>

im brand new to twine and i might be missing something but i want link them to specific animals which i made a passage for each object.

2 Answers

0 votes
by (23.6k points)
selected by
 
Best answer

Passage names are just strings and can be referenced as such. If the name of your passage is the same as - for example - $pet.name, you can say something like:

[[Buy|$pet.name ]]

Don't forget the space between $pet.name and the brackets. Twine will automatically try to create a passage called "$pet.name", but it can be deleted.

by (65.4k points)

In general, you should never put leading or trailing spaces around the passage name due to Twine 2 considering them significant while SugarCube does not.  In this case, adding a trailing space is completely unnecessary, so I'm unsure why it was even suggested.

Also.  If you're going to use a variable, as in this case, then it's also generally easier to bypass Twine 2's automatic passage creation feature by using the separate argument version of <<link>>, rather than using the link markup and then having to play delete-the-passage every time.

 

by (23.6k points)
I get an error when leaving out the space.
by (65.4k points)

I think you'll find that you're either mistaken or confused.  You may have run into an error at some point, but it's not related to this specific example.

Case in point, in the following example both uses of the link markup work just fine and will atttempt to take the player to the "Dogbert" passage:

<<set $pet to { name : "Dogbert" }>>
[[Test raw link markup|$pet.name]]
<<link [[Test link markup as macro argument|$pet.name]]>><</link>>

 

by (23.6k points)
Yeah - you're right. Have no idea why it didn't work before. It's the exact unchanged code.
+1 vote
by (65.4k points)

You can simply add a property to the pet object's which holds the name of the associated passage and then reference that in a link—e.g. something like $pet.passage.

Here's one example of how that's might look:

<<if $pcgold >= $pet.Price>>
	\<<link `'Purchase ' + $pet.name + ' for ' + $pet.Price` $pet.passage>><</link>>
<<else>>
	\You do not have enough to purchase it.
<</if>>

NOTE: I used the <<link>> macro there to avoid Twine 2's automatic passage creation feature.

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.
...