squiffy.story.go not working in a button

Hi all,
New to Squiffy (and loving it). I've googled around quite a bit for an answer here and can't seem to find anything. It's entirely possible I'm mixing JS and Squiffy incorrectly, any guidance would be appreciated.

I'm attempting to put a button at the bottom of my Section that allows users to check their 'inventory'. The inventory is a standalone section( [inventory] ) that functions as expected when a passage link is set to it. Here's my button setup:

<button type="button"
<button onClick=squiffy.story.go("inventory");>Inventory.</button>

The button displays as expected, but clicking it will not prompt the [inventory] passage.
I've also tried removing the button logic entirely and simply entering:

squiffy.story.go("inventory")

This also fails to trigger the [inventory] passage. Is there something I'm doing incorrectly with squiffy.story.go? Do I need to activate some additional js code in order to enable this?

Thank you!
Will


Out of my league here. Have you tried standard JS code in the button (like setting a boolean to true)? Does that work? Are there other squiffy commands you can also try?

Just trying to narrow down what could be the problem - I suck at JS code, frankly.


Your button is missing quotes. Does it help if you do:

<button onclick="squiffy.story.go('inventory');">Inventory.</button>

Looking at this again (thanks, spammer!) I see what I should have seen last time.

I believe the squiffy object is kept in a closure, so it only accessible within the javascript part of a section. For compatibility reasons, it isn't a global variable (global variables with the same name as an element ID confuse some browsers). So if you want a button like that in the text part of a section, it'd look something like:

[[some section]]:
    window.story = squiffy.story;

Here's the inventory button:
<button onclick="window.story.go('inventory');">Inventory.</button>

(the window variable refers to the browser window, so is accessible by all javascript within the window, whether it's in the script part or called from clicking on some HTML).

Also:

The inventory is a standalone section( [inventory] ) that functions as expected when a passage link is set to it.

Not sure what you mean there. Is inventory a section or a passage?
A section would start with [[inventory]]:. A passage would start with [inventory]:.

If you mean it's a passage, then squiffy.story.go isn't the function you want. In that case, the example would become:

[[some section]]:
    window.story = squiffy.story;

Here's the inventory button:
<button onclick="window.story.passage('inventory');">Inventory.</button>

[inventory]:
<hr/>
You're carrying a bunch of junk.

(I added an <hr/> there because clicking a passage link outputs an <hr/> by default, but calling squiffy.story.passage does not)


How do you make the Inventory available anywhere and not in the specific [[some section]]?

If I put it in the header [[]] then the button appears but as a passage [] it will not call it. As a section [] it does call it, but then I am stuck in that inventory now - how do I get "back"? i.e. if it is only in [[some section]] it continues ok, but I don't want to put the commands in every section...

I am not a javascript coder and also new to squiffy - I used to code on a mainframe until about 15 years ago so a little knowledge makes me dangerous...


In another thread (link) I posted a chunk of JS which I think should allow [passage links] to open a passage in the master section from any section.

So you could do:

[[]]:
Here are some links to the [inventory] and [your stats].

[inventory]:
Display the inventory here.

[your stats]:
display stats here

and it should work for every section. (Although it should be noted that if any section has its own [inventory]: passage, the link in the header will display that instead)

I've not tested it properly, so this is mostly a guess. But if I'm understanding the code I've read correctly, that should make it work.


This topic is now closed. Topics are closed after 180 days of inactivity.

Support

Forums