Howdy, Stranger!

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

Bug? in 1.4.2: Assigning an object in a link

edited December 2014 in Help! with 1.x
Hi, I'm having a little bit of a strange problem in Twine 1.4.2. I could be doing something wrong, but I'm pretty sure it's a bug.

I'm using the link syntax:

[quote][[passage name][$variable= "what to set the variable to"]]

and in one particular case, hitting the browser back button causes the "Sorry to interrupt, but this story's code has got itself into a mess." error.

The syntax that causes the error is:

[quote]&lt;&lt;set $my_obj = {var1: &quot;Hello&quot;, var2: &quot;world&quot;};&gt;&gt;\<br />[[Example Passage][$another_obj = $my_obj]]

The amazing thing is that

[quote][[Example Passage][$another_obj = {var1: &quot;Hello&quot;, var2: &quot;world&quot;}]]

works just fine. It's only if {var1: "Hello", var2: "world"} has been assigned to another $variable that things get weird.

I've attached a simple example.

Apologies if this bug is related to the known issue:

[quote]Bookmark link should be lazily computed

The bookmark link has proved to be a massive perf drain when a story uses JS objects in variables. It should really only be computed when the player actually clicks the link.
as noted on


  • Okay...So i have a similar problem when testing my story, in that when i reach particular point, i get that same error message and i cant move forward at all.

    But when i tried yours it...worked perfectly fine. I could move backwards on both links.

    I switched from Internet Explorer to Chrome and problems...reversed itself somehow.
    Yours showed exactly the problem you described, and mine worked (as in i could move forward past the choice now) but I also couldnt press the back button.

    I have no idea how to solve this and i need to assign my variable (causing the problem) to another variable.

    I guess chrome works for now though...
  • note: you should state in your topic which story format you are using as answers may be different for each one. Based on your TWS file I am going to assume you are using Sugarcane.

    Some background information:

    1. When the Reader moves from one Passage to another the story format's History system basically makes a copy of all the existing variables, the original variables are associated with the previous Passage in the History system and the copy is made available to the new Passage.
    This is done to make it easier to undo changes to variables if the Reader travels backward through the story.

    This can cause issues when a variable contains a value like a Javascript Object because although both of the passages look like they are referencing the same object (the value of $another_obj) in realty they are actually referencing two different objects which both have similar key/value pairs.

    2. The following code $another_obj = $my_obj is not assigning a copy of the contents (a javascript object) of $my_obj to the $another_obj variable, what it is doing is making both variable reference the same object:
    <<set $objA to {name: "Bob"}>>
    <<set $objB to $objA>>
    <<print $>>
    <<print $>>
    <<set $ to "Jane">>
    <<print $>>
    <<print $>>

    You have found a bug in the Sugarcane story format, when you click on the second link and the use the browser's back button, the following error appears in the developer console:
    TypeError: state.history[0] is null

    If you try the same test using the SugarCube story format instead you will not get the error.
Sign In or Register to comment.