I have previously used choicescript for writing, however, I found the lack of a node map really difficult and I had to write my own using other software to keep track of all of the important choices etc. Then I came across Twine, and saw something that offered a node map (yay!), but didn't offer something similar to fakechoice, which is basically giving the user choices which wouldn't really result in different paths.
I've been working on some javascript (which I have also posted about in the help forum
here), and with the assistance of the kind folk here and on stackoverflow, I have managed to cobble something together which seems to do everything I want. For example, if you would like to have a conversation with an NPC, but don't want to create multiple nodes to do this, then this is what the script is capable of.
Here's a demo of what it can do:
DropboxIt's running in sugarcane, and all of the text for the demo with the exception of the check variables passage at the end is in one passage.
This is NOT a custom macro for twine, as I'm certainly not at the level I need to be in understanding those to be able to make this into one, but I will probably begin to attempt to change it into a custom macro at some point. Anyway, I thought I would share the script in case anyone was interested.
Here's a link to the actual javascript:
fakechoice1.jsFor this to work, you have to use html which would look similar to this:
<div class="inlinechoice-0" id="0">
<a class="question" id="1">Question 1</a><br>
<a class="question" id="2">Question 2</a><br>
</div>
This presents the user with a list of options, which will disappear once one of the questions is clicked. The next piece of html would look like this:
<div class="answer-1">
You asked the first question.
</div>
<div class="answer-2">
You asked the second question.
</div>
Note that <a class="question" id="1"> would return <div class="answer-1">, so the numbering here is important.
Finally, you need this piece of html so that everything appears where it should.
<div id="dialogue_container"> </div>
<div id="append"><br>You've finished asking questions.<br>
The dialogue_container is where all of your chosen questions and answers will appear. The append div will show once there are no more questions and I guess is optional. In the example above I haven't nested any additional questions within the answers, but the demo link does do that. Inlinechoices begin at 0 and increment by 1, so if you were to nest them in an answer div you would call them inlinechoice-1 with an id of 1, and inlinechoice-2 etc. I'm not claiming that this is an elegant solution by any means, however, it's what I've managed to work out via a combination of google, stackoverflow and various Twine resources.
Currently, there are a few issues, which I am hoping to iron out.
Issue one is that I am having to place the javascript in an external .js to the twine .tws as I can't get it to work otherwise. I believe that I should be able to place the contents of the javascript into a script passage and simply call it using <<display>> as advised
here however, I couldn't get this to
work.
Issue two is spacing and breaks. If you check the demo, you'll find the spacing is a bit odd. There also appears to be some slight indentations going on for reasons I don't understand, and <<nobr>> and <<silently>> don't really seem to help.Issue three is twine variables. The javascript currently passes all of the choices made in a passage to an array, which is updated once you leave the passage. This is more of a work around than a desired solution though, it would be nice to update the array in passage. In the mean time, to pick up if certain choices were made, I'll probably use the methods described on here, which should suffice my needs for the moment. Of all of the issues, this is probably the one I can live with quite happily. Issue four is that I want to make this into a custom macro. To get it to work currently, there's quite a lot of clumsy html required, and I'm sure I just need to do something like replace and custom macro tags with the required html rather than having it directly in the passage. Anyway, I'm posting this here in case it's of any use to anyone, and I'll probably use this thread to record any updates and improvements. I know this is useful certainly for me, and hopefully it will be for others.
Comments
So, I clicked the Dropbox link again. No error, but nothing happened when I clicked the links in the story.
So, I downloaded it and used the latest version of Chrome, Firefox and IE to open it locally. Clicking the links did nothing at all, but again no error.
I opened it up in Twine and took a look, but it seemed there were multiple different inlinechoice DIV's, so I didn't mess with it further.
Windows 7 64-bit.
Maybe something was wrong with the jQuery or being on Dropbox? Maybe my computer's just stupid.
I have noticed another weird issue though...if you accidentally click in the gap between one of the choices, everything disappears, even if you don't actually click a choice which I guess is because you're clicking within the inlinechoice div, even if you're not clicking on anything...so I need to fix that too. Hah. Oh well, I'm further along than I was two weeks ago anyway.
Thanks for trying so many options with this though, it was certainly my error, and nothing to do with you (or your PC)!
Edit: Managed to fix the clicking on the gap issue.
Pretty cool, Bawpie!
I hope you will be able to make this into a macro at some point down the track, it would be mighty handy for doing a lot of dialogue in a game and save time. That would be awesome. I am sure many Twine users will use it in their games.
I tried out the demo and it worked fine via the dropbox link, but when I downloaded the html and imported it into Twine and ran it, but it just outputted all the dialogue text at once. So I am guessing this is 'issue one' you are talking about?
Issue one refers to this example: Internal JS Demo
And this is a link to the non-working tws: here
Basically, in that example you can click on the links, but nothing happens. I think what you've encountered is possibly because importing the html into twine hasn't included the .css styling? If you want to see how it looks in Twine, this is a link to the working tws file: here
Thanks though, it's good to know others would find this useful.
HTML Link
TWS Link
Basically, I've been able to cut down the amount of html required to get this to work. So now, the syntax looks like this: However, I'm still having to use a script to externally load the javascript that does all of the work (the custom macro just allows me to use the custom tags), and I'm also still having to add the <div id="dialogue_container"> </div> into any passage that uses it, so still not ideal. In all, I'd say it's about 75% there at the moment. Currently I can only figure out how to assign one variable at a time inside the <<question>> tag, but hopefully someone over in the help forum can help me with that.
Should be possible to write one that'll work with a conversation in a javascript object, which means you could dump the whole thing into a macro...
I've tried putting your example into Twine (with a couple of changes such as keeping the <<set $question = 1>> in a separate passage), but couldn't get it to work although I'm not sure why. With this method, you'd also have to spread the choices over at least two passages if you had any nesting, and what the posted code achieves it keeping it all in one passage.
Here's what I tried (in a passage titled self): But it doesn't seem to set the variable to change when clicking on answer 1.1 or 1.2.
What would of been nice would be if you could combine <<choice [[link syntax]]>> and [[Continue|Questions][$question = 5;$answer4 =0]] so you can tack on variables and have the questions only show once but it doesn't seem possible.
I created a demo (sugarcane) showing what I have done, there are two types of question/answer sets one where there are three questions the player can ask a NPC and the other where the player is being asked a question and has two possible answers to choose from.
I have placed comments that are fairly obvious in some of the passages for clarity for everyone (i hope they make sense). There may be a more refined method but at least this works. However this might get hard to manage in a big game. The only bit I need to polish is my counter for player asking npc questions can easily count if the player clicks the same question link three times before moving onto next question. The passages have been named as topic of question or answer as a placeholder, I suppose this would be the way to manage topics.
Conversation Demo:
https://www.mediafire.com/?mshytnb7hyz09yy
The aim with my system was to have something that wouldn't require multiple passages, so I guess it's less for a full on conversation, and more for incidental dialogues which perhaps don't change anything immediately and appear quite linear, but may silently adjust the characters opinion of you. So, for example:
You greet Joe with a smile.
You nod at Joe.
You scowl at Joe.
3 options, but actually, I don't want to write a lot of if statements, I just want Joe to respond in one of three ways:
Joe smiles back at you.
Joe nods back at you.
Joe scowls back.
Then I want the passage to continue...
"Hey, you two!" your boss yells. "Get to work!"
Using Twine's traditional methods, this would require extensive use of macros in ways they weren't quite intended, or multiple passages. So I guess that's what I'm aiming to make a little easier.
Thanks to The Pixie and MadExile, I'm now able to set multiple variables when a particular question is asked.
This is achieved with this syntax: <<question 1 variable "variablevalue" variable2 "variablevalue2">>
So, I'd say I'm about 80% there. Just need to get rid of the html dialogue_container and figure out how to integrate my custom .js.
It's definitely interesting to see how others would approach this though.
Edit: Just added the dialogue container div into the choiceblock macro, so no need to declare it in the passage any more.
Demo here: HTML Example | TWS Example
Place in a Passage called converse: In your setup, you need to define your conversation: Create a Passage to hold it - MeetJoe You then need a passage called Work that the conversation will pass control to when it ends. At the start of work you need to include: You can check which conversation nodes were visited with $meetjoe[node].visited it'll be 1 if that choice was picked.
I've tweaked my macro a little, so there is no need for any custom html directly in passage, as the macro will handle it. I'm still having to call the fakechoice1.js via the LoadJS macro but rather than do it manually, it's integrated into the dialoguemacro code. I think it's about as seamless as I can make it for now. For this to work you need to have the following saved as a .js script saved in the same folder as your game (it should be called fakechoice1):
Then you need 2 script passages:
My dialogue macro script: Dan Cox's script for loading external .js files. And finally, in a stylesheet passage you'd need this:
So, a passage would look like this: Finally, you need to make sure Jquery is enabled in the storysettings passage.
The append part is entirely optional and should only appear once all choices have been exhausted (one choice per choiceblock), but every passage that has a choiceblock should start with <<choiceblock 1>>. Any additional choiceblocks in a passage should have a different id, (i.e. 2, 3, 4 etc.).
You can set multiple variables in each question (which will only be set when that question is clicked), but you must name your variable without the $ sigil. It'd be nice to fix that at some point, but it's purely superficial.
For me, this is a lot easier to understand and read then looking at lots of if statements or custom html, but I guess everyone is different. It's certainly not elegant, but it does appear to work. There isn't much error handling built into either the fakechoice1.js or the custom macros, so I guess it'd be fairly easy to mess it up, but all of the examples I've tried so far seem to work.
Example files: TWS File | HTML File
There is a technical problem with this story (dialogue: unterminated regular expression literal).You may be able to continue playing, but some parts may not work properly.