Howdy, Stranger!

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

2.0 cycling TypeError problem

Hey all, wondering if anyone could help with this. I was trying to do a cycling text on click thing in 2.0, and tried to use some code that L showed me on another post.

L wrote:

This can sort-of be done using this:

You can't accept second place! You're no |phrase>[short-nosed horse!] It's back to training for you!
(click-replace: ?phrase)[(set: $cycle to (it + 1) % 3) (if: $cycle is 0)[short-nosed horse!](else-if: $cycle is 1)[silver athlete!](else-if: $cycle is 2)[partner to greatness!]]
but this is unsightly code which I do not recommend.


This may be unsightly, but hey, I'm not going to come up with anything pretty so I tried to go with it. Also, do I ever love his example text. Unfortunately, I end up with
"You can't accept second place! You're no TypeError: undefined isn't the same type of data as 1 isn't the same type of data as 3 short-nosed horse! It's back to training for you!" after the first clicked link. Is there another way to get around this?

Comments

  • The error is telling you that your $cycle variable is not the same data type as the value (the number 3) within your code.

    Generally this is the result of your variable not being initialized before being used, in this case as part of an arithmetic expression. (the (it + 1) % 3 part of the (set:) macro. To fix this assign a default value to your variables before hand.

    (set: $cycle to 0)

    You can't accept second place! You're no |phrase>[short-nosed horse!] It's back to training for you!
    (click-replace: ?phrase)[(set: $cycle to (it + 1) % 3) (if: $cycle is 0)[short-nosed horse!](else-if: $cycle is 1)[silver athlete!](else-if: $cycle is 2)[partner to greatness!]]
    WARNING: If you are using the online Twine 2 beta found here then after you fix your code as suggested above then the next error you will see when you click on the link will be "e is not an object". This is caused by using the "it" reference within your (set: $cycle to (it + 1) % 3) and is the result of a bug in the version of the Hawlore Story Format being used.

    To fix this you will have to download the Twine 2 beta, then download the latest version of Harlowe, and then manually update the copy of Harlowe within your local copy of Twine 2 beta with the version of Harlowe your downloaded which is not a simple process.
  • Ok, cool. Thanks for the help, greyelf!
  • greyelf wrote:

    To fix this you will have to download the Twine 2 beta, then download the latest version of Harlowe, and then manually update the copy of Harlowe within your local copy of Twine 2 beta with the version of Harlowe your downloaded which is not a simple process.


    I took a look at the Harlowe repository but couldn't see any indication on how to build Harlowe and put it inside Twine. Would you please tell me at least what's the starting point? Does the whole thing build to the format.js file that you find in the Harlowe folder within Twine?

    This is quite important for me because I'm trying to learn Twine and it wouldn't make sense that I have to learn Twine 1 when the new version is so close. Moreover, I'm on Linux. But the Twine 2 beta hasn't been updated and some bad bugs (such as not being able to increase a variable) are still there.
  • We are about to take a trip down the rabbit hole Alice!

    The Harlowe story format project uses a tool named Grunt to generate its release file(s), this tool in turn requires Nodejs and NPM to be installed.

    Once all of the above has been installed (and maybe configured) correctly you will be able to open a command shell, change to the directory you extracted the Harlowe source into and issue the following four commands:

    1. npm install
    Which will install all the nodejs modules used by the Harlowe project. This could take a while depending on your internet connection.

    2. grunt release
    This will create the docs directory as well as its files.

    3. grunt
    This will create the build directory as well as its files.

    4. grunt runtime
    This will create the dist directory and the format.js file within that directory, it is this file that you will need to include into Twine 2 beta.

    edited: to include the npm install command and to add the extra grunt commands needed to create dist/format.js file.
  • Got it working perfectly, and finally I can increase variables. The info about npm should be pinned somewhere. Thanks!
  • One extra thing to note is that the Harlowe story format is still being developed, features are being added/removed and bugs fixed on a almost daily bases. You may want to keep track of these changes and download a newer version as necessary.
Sign In or Register to comment.