Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Tracking answers with Twine

Hello,

I'm creating a game for my student newspaper using Twine. I'm wondering if there is a way to track the answers that are given so that I can tally them up and give the users a bit of a resolution. The layout of the game is much like a board game. Each space has it's own personal question and a selection of answers (expecting the user to be honest). Some questions allow the users to advance farther than others, and the goal is to complete the game in as few spaces as possible.

But in order for that to work, I need to count how many spaces the player takes.

I've been searching the Internet for hours and haven't come up with anything.


Is it possible to do this?
Thanks,
Daren

Comments

  • Variables. You heard it here first!

    In each space that you want counted, type in code similar to this:
    <<set $counter = $counter + 1>>
    Or,
    <<set $spaces += 1>>
    Two ways to code the same thing. I use the first.

    Each time the passage is displayed, it will add 1 to the $counter variable. You can call the variable anything you'd like as long as it's one word and doesn't start with a number and has the dollar sign before it. You can call it "$spaces" or "$spacesCounter" or "$n" or whatever.

    When you want to print how many spaces the player has moved type code into the passage similar to this:
    <<print $counter>>
    While we're talking about it, there are also "setter links." It's a little more advanced, but still the basics. You can use a link to set a variable.

    Here is your normal story link:
    [[Link Passage Title]]
    Anther way to write a link:
    [[Display Text|Link Passage Title]]
    Finally, here we have a setter link that sets a variable when the player clicks it:
    [[Display Text|Link Passage Title][$foo = 1]]
    So, for the above link code, the game will display "Display Text," will take the player to the "Link Passage Title" passage, and set $foo to '1'.

    Attached is an example of all this in a Twine story file.

    Hope that helps!


  • Does every space you visit consist of the same number of passages? If so, calling the turns() function might be all you need.
  • Thanks Sharpe, Those suggestion worked like a charm!

    There are some spaces that I didn't want to count, so I had to set up the counter for the appropriate pages.
  • You might want to download my attached game file above, play it and review the code. I provided an example of how I would use setter links in a game like the one you described.
  • I downloaded it and took a peak. Thanks for creating that, it is very helpful!

    Now that I have that tracking set up, is there a way that I can export the results so that I can compile some of the data? (Nothing personal, and there is a notice on the first page that some of the answers may be saved).

    I've been looking at the Google Spreadsheet Logging Macro, but I'm not sure how to adjust the values to the ones that I am using.


    Thanks again,
    Daren
  • Maybe, but I can't help you there.

    Did you know Twine and JavaScript can evaluate math expressions? Like, <<set $a = $b + $c>> will add the variables $b and $c together and set that sum to variable $a. You can do division and multiplication, etc.
  • That could work out well. How could I log the answers on another page? This way other users could see the results from everyone else as well.
  • Man, that's just going well beyond the scope of Twine basics, and that's all the help I'm qualified to give. I can think of some ways, but it's just too far out. Perhaps someone else will come along and help you in this regard.
  • Fair enough. I have an idea, and I'll let you know if it works. If it does, it'll be an extremely simple solution (new variable that adds up the old ones).

    *edit:
    Doesn't look like that solution worked. Does anybody else have a suggestion? Otherwise I'm going to start looking at javascript and hoping I can make it work.

    Thanks
    Daren
  • [quote author=Daren_Z link=topic=1467.msg2454#msg2454 date=1392241567]
    Fair enough. I have an idea, and I'll let you know if it works. If it does, it'll be an extremely simple solution (new variable that adds up the old ones).


    If you restart the game for a new player, all variables will be cleared. You could set your counter variable back to 0 and send the new player back to start, though.

    If you knew you were going to have, say, four players, you could set up variables like $player1 and $player2, etc. Then, at the end of the game, you would do something like this for each player:
    <<set $player1 = $score>>
    You'll almost certainly need to learn about if conditional branches to make this work, though.

    The part I don't want to get into is external data such as databases and spreadsheets and such.
  • You can do HTTP POSTs from JavaScript and have a CGI or PHP or similar script on a server to handle the POST requests and log the data. It's not something that is easy to explain in a few paragraphs; if you haven't done this kind of thing before, you'd have to learn quite a bit to pull it off. None of it is particularly difficult, but there are a lot of parts involved.
  • mth wrote:

    You can do HTTP POSTs from JavaScript and have a CGI or PHP or similar script on a server to handle the POST requests and log the data. It's not something that is easy to explain in a few paragraphs; if you haven't done this kind of thing before, you'd have to learn quite a bit to pull it off. None of it is particularly difficult, but there are a lot of parts involved.


    Thanks for the response mth. Is there any particular guide on getting started with this? I am comfortable using code, albeit my experience is mostly with java.
  • If you know Java and have a server you can run it on, have a look at servlets for handling POST requests. You can use for example Apache Tomcat to run them in.

    XMLHttpRequest is probably the most versatile way to do HTTP requests in JavaScript. Despite the name, you can use it for other data formats than XML too. There are some annoying differences between browsers, so probably the easiest way to use it is through jQuery.
  • Thanks for the response, I'm looking into that right now. I'll make the game live for now and omit the tracking aspects and hopefully have those up within the next couple of days.

    I'll post back here if I have anymore questions,
    Daren
  • If you don't have access to a server + database, you could also use google spreadsheets to store and retrieve information.
  • Erik wrote:

    If you don't have access to a server + database, you could also use google spreadsheets to store and retrieve information.

    He said he wanted to use Google Spreadsheets.
  • Ah, didn't see that and didn't know there was a macro.
  • You don't really need a database to collect simple data: you could just append the results to a plain text file, using comma separated values if you want to be able to easily import it.

    There might be a way to access Google Spreadsheets using jQuery and without having your own server, but I have no experience with that.
  • I know I'd like to read a tutorial on the simplest way to have a "scoreboard" or something of that nature to a website. Say there is a Twine game with a $score variable; how that could be posted to a live website, I would like to know.
  • mth wrote:

    You don't really need a database to collect simple data: you could just append the results to a plain text file, using comma separated values if you want to be able to easily import it.

    That's true, and if you have access to a server that's the easiest way to do it, I think.

    mth wrote:
    There might be a way to access Google Spreadsheets using jQuery and without having your own server, but I have no experience with that.

    I have used Google Spreadsheets extensively as a way to display data using javascript + HTML (publish the sheet and read data in via JSON feed), but come to think of it I have never actually logged data that way. Authentication might require server-side files, and if you can do that, you might as well just use php to write a text file.
  • Sharpe wrote:

    I know I'd like to read a tutorial on the simplest way to have a "scoreboard" or something of that nature to a website. Say there is a Twine game with a $score variable; how that could be posted to a live website, I would like to know.
    +1 because that would be AWESOME
  • Not sure if you've already seen this, but looks like it could help with what you want to do:  http://blog.devonbaumgarten.com/twine-macros-for-google-drive-spreadsheets/
Sign In or Register to comment.