0 votes
by (310 points)

(if: $mood is 1)[
(live: 1s)[(stop:)(t8n:"dissolve")+(t8n-time:3s)[abc]]
]
(else-if: $mood is -1)[
(live: 1s)[(stop:)(t8n:"dissolve")+(t8n-time:3s)[def]]
]

On the previous page, I use this to assign the variables when clicking on a link, which also takes the player to the passage containing the above (named "10").

(live: 8s)[(stop:)(t8n:"dissolve")+(t8n-time:2s)[(link: "123")[\
	(set: $mood1 to $mood1 + 1)\
	(go-to: "10")\
]]]

(live: 8s)[(stop:)(t8n:"dissolve")+(t8n-time:2s)[(link: "456")[\
	(set: $mood1 to $mood1 - 1)\
	(go-to: "10")\
]]]

(live: 8s)[(stop:)(t8n:"dissolve")+(t8n-time:2s)[(link: "789")[\
	(set: $mood1 to 0)\
	(go-to: "10")\
]]]

This does set the variables, but when I go to the next page, nothing happens. Nothing is printed. I tried to include a final (else:) statement that would print something else, and that seemed to always print no matter what the value of the variable was. It looked like this:

(else:)[
(live: 1s)[(stop:)(t8n:"dissolve")+(t8n-time:3s)[ghi]]
]

I've obviously changed what the text actually is to make it a lot neater. 

 

Thanks a bunch for any help. :)

 

2 Answers

+2 votes
by (159k points)
selected by
 
Best answer

In your 2nd example you have 3 timers with the same duration active at the same time, and this isn't a good idea.

Timers are an expensive process and can interfere with a user's ability to interact with the page, you should try to have as few of them as possible active at the same time.

The following is a modified copy of your 2nd example, it uses a single (live:) macro and a named hook to achieve the same result. Using a named hook this way also allows for better control of the placement / formating of dynamically revealed output.

|output>[]
(live: 8s)[
	(stop:)
	(append: ?output)[{
		(t8n:"dissolve")+(t8n-time:2s)[
			(link: "123")[
				(set: $mood1 to $mood1 + 1)
				(go-to: "10")
			]
			<br><br>
			(link: "456")[
				(set: $mood1 to $mood1 - 1)
				(go-to: "10")
			]
			<br><br>
			(link: "789")[
				(set: $mood1 to 0)
				(go-to: "10")
			]
		]
	}]
]


warning: Harlowe can have a timing issue when displaying block based HTML elements (like the <br> I am using), so you need to use CSS like the following in your Story Stylesheet area to modify how such block based elements are displayed.

br {
	display: inline-block;
	width: 100%;
}

... if you plan to use any block based elements (like DIV or TABLE or UL) then you will need to also add them to the CSS selector of the above rule. eg. to add DIV support change the above to

br, div {
	display: inline-block;
	width: 100%;
}

 

+1 vote
by (63.1k points)
You have two different variables, $mood and $mood1. Note that this is a terrible way to name variables because of how easy it is to mix up. I would suggest changing the names of the variables, not just "fixing" it.
by (310 points)
edited by

Yes, this definitely is a mistake, but doesn't appear on the code, just when I was copying it onto the forum (which of course you couldn't have known, so that's 100% on me). If you think it's terrible because I might get it mixed up down the line, then that isn't an issue because of my structure and planning, but if there's another reason, I'd like to hear it.

Thanks either way. :D

 

Edit: upon relaunching Twine (and I guess restarting my computer), the problem seemed to fix itself. I've had this issue with other programs (such as Quest), but not with Twine yet.

Edit 2: "but doesn't appear on the code", by which I mean that the variable is named "mood1" in all cases, a variable called "mood" doesn't exist.

by (63.1k points)

If it's $mood1, then I assume that there's a $mood2. My suggestion is that this naming convention is bad. If you believe you need numbered variables because the related vars encapsulate related functionality, then you are probably better served by a datamap or array. If instead these variables are meant to be different, for example, if $mood1 represents the mood of character 1, or the angry mood or something, more specific names will help you prevent issues where you can accidentally write $mood2 or something when you mean $mood1. 

If you think it's terrible because I might get it mixed up down the line, then that isn't an issue because of my structure and planning...

You can do what you want, it's not my game and I don't have to work on it, so it doesn't matter to me. But I would point out that this is a mistake you've already made, even if you don't believe it counts because it was made in a question and not in "real" code. Structure and planning are not an effective counter, in my personal experience, to the human capacity for making mistakes. It's like not wearing a seatbelt because you're confident in your driving ability. Again, this is just my opinion. You may be an excellent and experienced programmer who never creates hard to find bugs, but this is still advice I'd give to anyone who has variables named like this.

If there's just a $mood1 variable, and no $mood or $mood2, etc, then I still don't get the naming convention but at least there's some uniqueness here, so maybe it won't be an issue for you. 

Edit: upon relaunching Twine (and I guess restarting my computer), the problem seemed to fix itself. I've had this issue with other programs (such as Quest), but not with Twine yet.

There are a few potential culprits, one is that you potentially forgot to refresh or close and reopen the test or play view in Twine 2, and the other is a bit more nefarious, sometimes your browser will cache an older version of the story even through reloads. You can fix this by hard reloading with CTRL + F5. I believe the application version is also susceptible to this behavior, but I'm not sure. Regardless, as long as the issue is solved, that's good. 

I'd also like to support @Greyelf's suggestions about limiting the instances of running timers. It wasn't something that was directly related to the apparent variable name issue I erroneously thought was the problem, but it is also good advice, if unsolicited, much like my advice about changing the variable names. 

...