Howdy, Stranger!

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

Twine (Protagonist) works in Chrome but not in Editor

Hi, I'm using the Protagonist story format (here), which is a bit similar to Snowman (I think), and the desktop app (2.0.8), on Windows 8.1

I'm trying to implement a character start screen, so I have a passage that lets you choose some options (using a cyclinglink implementation that I coded, and a "contenteditable" textbox), which works fine, but on the next passage, when I try to access the Player variables I just set, in Chrome (after I've published to file), it works absolutely fine, however in the app, when I press Play, the first screen works fine, but when I click the link to the next screen, if I'm trying to access a Player variable, the link does nothing (if I delete the bit accessing the variable, it works fine)

My Story Javascript
window.Player =
{
	Name: "",
	HairStyle: "",
	HairColour: ""
};
	
window.nextCyclingLink = function nextCyclingLink(thisLink, i)
{	
	var cyclingLinkObject = JSON.parse(thisLink.dataset.cyclinglink);
	var optionsArray = cyclingLinkObject.options;
	var current = thisLink.innerHTML;
	var currentIndex = optionsArray.indexOf(current);

	if (currentIndex >= (optionsArray.length - 1) || currentIndex == -1)
	{
		currentIndex = 0;
	}
	else
	{
		currentIndex++;
	}
	thisLink.innerHTML = optionsArray[currentIndex];
	eval(cyclingLinkObject.variable + " = " + "'" + optionsArray[currentIndex] + "'");
};

window.editableVariable = function editableVariable(thisEditable)
{
	if (thisEditable.getAttribute("data-variable") != "undefined")
	{
		eval(thisEditable.dataset.variable + " = " + "'" + thisEditable.innerHTML + "'");	
	}
};

_$(function()
{
	var cyclingLinks = document.querySelectorAll("[data-cyclinglink]");
	for(var i = 0; i < cyclingLinks.length; i++)
	{	
		cyclingLinks[i].href = "javascript:;";
		nextCyclingLink(cyclingLinks[i]);
		cyclingLinks[i].addEventListener("click", function()
		{
			nextCyclingLink(this);
		}, false);
	}
	
	var editable = document.querySelectorAll("[contenteditable='true']");
	for (var i = 0; i < editable.length; i++)
	{
		editableVariable(editable[i]);
		editable[i].addEventListener("blur", function()
		{
			editableVariable(this);
		}, false); 
	}
});


My Init Passage
There is a gentle breeze, it makes the curtains flutter.
You gaze into the shard of crystal in front of you.
Your
<a id="player_hair_style"
data-cyclinglink='{ "variable": "Player.HairStyle",
"options": [
"long, wavy mane",
"short, spiky do",
"slick, smooth bob"
]}'/>
(<a id="player_hair_colour"
data-cyclinglink='{ "variable": "Player.HairColour",
"options": [
"pure white, like the snow on the mountains",
"turquoise, the same colour as the expansive sea",
"dusky green, like the forest moss",
"bright red, like the dying embers of the fire"
]}'/>)
obscures the reflection of your face.

Your name is <span id="player_name" data-variable="Player.Name" contenteditable="true">jemonn</span>

[[Confirm|Start]]

My Start Passage (the one that doesn't work)
blah blah blah

<%= Player.HairStyle %>

I can't see why it won't work, but having to export to Chrome every time just to test it is quite annoying.

Comments

  • edited July 2015
    The current release of Protagonist (1.0.0-beta.2) refuses to install for some reason, which I do not have time to look into now, and apparently at least some versions prior to that had broken JavaScript when you published. And yes, It is a fork of Snowman.

    Just looking at the code I notice a few things.

    In your Story JavaScript, the following:
    _$(function()
    
    Should probably be this:
    $(function()
    
    After that change, it all worked in Snowman for me, so I assume it'll work in Protagonist (unless you're using a broken version).


    This isn't the cause of your issues, however, anchors are not void elements. The following is incorrect:
    <a …/>
    
    You should be doing this:
    <a …></a>
    
    Even if they're going to be programmatically updated by your code, and even if the browser accepts them that way, you should construct them properly.

    jemonn wrote: »
    […] having to export to Chrome every time just to test it is quite annoying.
    Why aren't you using the the Test and/or Play buttons (bottom right of the story editor)?
  • In your Story JavaScript, the following:
    _$(function()
    
    Should probably be this:
    $(function()
    
    After that change, it all worked in Snowman for me, so I assume it'll work in Protagonist (unless you're using a broken version).
    I had to change it to _$ for some reason for it to work. The code is called, so I'm assuming that it's okay. Chrome says that $ is undefined.
    This isn't the cause of your issues, however, anchors are not void elements. The following is incorrect:
    <a …/>
    
    You should be doing this:
    <a …></a>
    
    Even if they're going to be programmatically updated by your code, and even if the browser accepts them that way, you should construct them properly.
    Ah thanks, I didn't realies that you couldn't do that! As you said, it didn't fix anything, but better to try and do things right.
    Why aren't you using the the Test and/or Play buttons (bottom right of the story editor)?
    The problem I'm having is that the built-in test/play screen (on the desktop app) don't work with my code, however when I manually open the compiled .html file in Chrome, my code works fine.

    I just changed to Snowman and it worked fine straight away, so whatever issue I'm having, it's related to Protagonist.
  • edited July 2015
    jemonn wrote: »
    In your Story JavaScript, the following:
    _$(function()
    
    Should probably be this:
    $(function()
    
    After that change, it all worked in Snowman for me, so I assume it'll work in Protagonist (unless you're using a broken version).
    I had to change it to _$ for some reason for it to work. The code is called, so I'm assuming that it's okay. Chrome says that $ is undefined.
    That has to be a bug in the version of Protagonist you're using. As far as I know, _$ shouldn't be anything and $ is the alias for jQuery (even in Protagonist).

    jemonn wrote: »
    The problem I'm having is that the built-in test/play screen (on the desktop app) don't work with my code, however when I manually open the compiled .html file in Chrome, my code works fine.
    I used Play just now to test in Snowman in the exact same version of Twine 2 you say you're using (2.0.8 executable version). /shrug


    I think all your issue may stem from a busted version of Protagonist.
  • I used Play just now to test in Snowman in the exact same version of Twine 2 you say you're using (2.0.8 executable version). /shrug


    I think all your issue may stem from a busted version of Protagonist.

    Yeah, now I've switched to Snowman I can use Play again. :)
Sign In or Register to comment.