0 votes
asked by (2.2k points)
edited by

I'm using the adventures format from github that I found here and from what I've read so far I can't find an answer to my question but it's also a little specific so I didn't really expect to find it.

I'm using the changing player's name with a html text box and I was wondering if it was possible for the second passage to react to the input depending on whether or not the player actually put in a name. I want it to say something like "if you won't give your name I'll assign one to you".

I think the best way would to be using an if true statement like 'if ==' but I just don't know what I'd put after that.

my code for the first passage works and it is thus

<%story.config.displayCharacterPanel = false;%>

[... story text ...]

<input onchange="character.name = this.value">

[[Give your name|001]] 

I put vvv in the second passage to see if it would work but it did not, so I'm wondering what a competent person would suggest for this.

<% if (character.name = this.value == "") { 
%> [input response for blank input box] <% 
} %>

I also want it to show the chosen name (if the player leaves the box blank) in the little character panel but if it's left blank the panel will be blank as well. 

Alternatively, how would I go about making it show one response for a lack of input and something else for input. An if else statement? That's what I'm thinking but I don't entirely know.

If <%= character.name %> is used even when there's no input it'll show the default name but the panel will still be blank so there's something wrong there there. Edit: turns out even with input the name still doesn't show up on the character panel but it does change the default name when printing it to screen, so that's wonky. I was apparently setting it to blank >.> my bad

Also, as a side question, I understand that this format is based off of snowman and I was wondering if someone can link me to its documentation? I'm pretty shiznit with javascript and all that jazz so I was looking for the macros and shiz with example usage but I can't really figure out how to and github is like a giant maze for me in general so trying to figure out snowman's github is like two pegs worse. I just want examples of what I can do with it all to supplement adventure's documentation which is very thin.

1 Answer

+1 vote
answered by (120k points)
selected by
Best answer

I haven't used that story format and I am a little pressed for time ATM so the following hasn't been tested.

Based on your input element example I believe the value entered by the Reader is being stored within the 'name' property of the 'character' object, eg. character.name

This means that your if statement should be checking the current value of the same thing.

<% if (character.name == "") { 
%> [input response for blank input box] <% 
} %>

EDIT: I forgot to answer your second question.

The main page of the Twine Wiki contains a link to the Snowman documentation (such as there is), and the a link to the Twine Wiki can be found either in the Top Right side-bar of this Q/A web-site or on the main page of the Official Twine web-site.

(** I should admit I had to fix the link to the Snowman documentation because it incorrectly referenced the old Bitbucket repository, which no longer exists.)

commented by (2.2k points)
That does indeed make more sense to do, I can't believe I didn't think of that. I have tested it and it doesn't work. Still gives the default name and doesn't show the text intended for the lack of input. Perhaps the double quotes is what doesn't work? Good news though, it got rid of my blank space on the character panel so that's dandy.
commented by (120k points)
I edited my answer to include information about the Snowman documentation.
commented by (120k points)
If I had to guess what the problem was I would start with the assumption that either:

a. the onchange event handler on the input element wasn't actually working as intended.

b. the character.name variable either doesn't exist or isn't within the Scope of the input element..
commented by (2.2k points)

I've seen the github but I don't know where I can find just a list of what it can do and use with examples because the guide it lists is a small txt file with like seven lines of text and I don't know where to find anything like what I want. Would the two links the jquery and underscore be what I was looking for?

<% if (character.name == "") { %> input repsonse for blank input box <% } %>

is what I've been using with your change and I don't know what either of your assumptions mean... or how I'd go about doing anything for them.

commented by (120k points)

I installed the Adventures story format and tested your original First Passage example.

<% story.config.displayCharacterPanel = false; %>

[... story text ...]

<input onchange="character.name = this.value">

[[Give your name|001]]

... using the following in the 001 passage.

character name: <%= character.name %>

... and if I entered a name and selected the "Give your name" button then the next passage displayed the name I entered. If I selected button without entering a name then the next passage displayed the default character name (Aramis), which makes sense because no onchange event occurred (because no value was entered into the input field)

If I change the default value of the character.name property to an empty String ""

	story.config.displayCharacterPanel = false;
	character.name = "";

[... story text ...]

<input onchange="character.name = this.value">

[[Give your name|001]]

... and select the "Give your name" button without entering a name, then the corrected IF statement example in my original answer will display the "input response for blank input box" message. Which makes sense because that statement is now testing for the (new) default value of the character.name property.

 I don't know where I can find just a list of what it can do and use with examples

As explain on the Snowman repository's main page that story format is aimed at people who already know Javascript, and the developer assumes that people using it are able to read the story format's source code to learn anything not explained on that main page. It is also assumed that people using it either: already have knowledge of jQuery & Underscore; or are able to learn about these frameworks from the relevant (linked) web-sites.

Besides the repository the only other web-site I know of that contains Snowman examples is the new Twine Cookbook repository, but I am not sure if that is open for general use yet.

commented by (2.2k points)
Thank you! that was super helpful, I've applied the code and it works wonders! and I found the cook book and it seems pretty helpful, I'll try to read through and learn the jquery and underscore information. Thanks.
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.