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
In each space that you want counted, type in code similar to this: Or, 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: 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: Anther way to write a link: Finally, here we have a setter link that sets a variable when the player clicks it: 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!
There are some spaces that I didn't want to count, so I had to set up the counter for the appropriate pages.
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
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.
*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
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: 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.
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.
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.
I'll post back here if I have anymore questions,
Daren
He said he wanted to use Google Spreadsheets.
There might be a way to access Google Spreadsheets using jQuery and without having your own server, but I have no experience with that.
That's true, and if you have access to a server that's the easiest way to do it, I think.
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.