0 votes
by (260 points)
edited by
I have created a semi-functional inventory that seems to work fine. The only issue, is that when "Check inventory" is clicked, the contents are viewed like this    Nightstick, Knife

When I want them to be viewed like this

-Nightstick

-Knife

This is what is within my inventory code.

<h2>Inventory</h2>
 

(print: $inv.join())

I have screenshots I can send (don't know how to place them here) to show how I've coded the inventory and how my if statements work. I know I'm doing something wrong somewhere as I am new to coding.

How can I fix this problem?

1 Answer

+1 vote
by (159k points)
selected by
 
Best answer

Please use the "Insert Code Snippet" button in the comment tool bar when you add code examples to your question/comments.

Based on the fact you are calling the JavaScript <Array>.join() function in your example I will assume your $inv variable is an Array.

You can use Harlowe's (for:) macro to loop through the elements contained within an Array, which you can then output to the page like so.

<h2>Inventory</h2>\
{
(for: each _item, ...$inv)[
<br>- _item
]
}


WARNING: Due to how Halowe implements its Passage Transitioning there is a timing issue when displaying block based HTML elements (like your <h2> element), to get overcome this issue you need to use CSS to change how such elements are displayed. Place CSS like the following within your project's Story Stylesheet area.

div, h1, h2 {
	display: inline-block;
	width: 100%;
}

note: If you wish to use other block based elements than the three I have included in the above CSS then you will need to add them to that list.

by (260 points)

Thank you for your help. That certainly fixed my problem!

I have one last question if you can spare another moment. 

 

I have been using this code to display a short flavor text for the item in question. 

(click: "Nightstick")[(display: "Nightstick details")]

 

How can I just make it so when they click on the link it actually brings them to a separate page with the information on that item?

I only ask because the way that the flavor text is presented isn't to my liking. It appears much further below the item itself and only in the order for which I have coded it.

 

by (159k points)

Whenever possible use a (link:) related macro instead of a (click:) related one.

You can use either a Markup based Link or a Macro based Link to do what you want.
(untested)

[[Link Text->Target Passage Name]]

(link-goto: "Link Text", "Target Passage Name")

(link: "Link Text")[
	(go-to: "Target Passage Name")
]

 

by (260 points)

 

The right combination that I was looking for ended up being 

(click: "Nightstick")[(go-to: "Nightstick details")]

 

Looks simple enough, but I just couldn't manage to figure it out. 

Thanks again.

...