Howdy, Stranger!

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

I suck at scripting ...


... So can a friendly soul show me how to create a function in a script passage, and then call it from a regular passage?

(Yes, I'm at the 'hello world' stage)

Also, what does :: mean?

Comments

  • Which story format are you using and what are you hoping to accomplish?  Yes, the answers to both really do matter.


    Shloo wrote:

    Also, what does :: mean?


    [EDIT] As others have noted below, if you've seen it someplace Twine/Twee related, on these forums or elsewhere, then it could be the start of a passage in Twee source notation (details by the others below). [/EDIT]

    Double colon?  Where did you see that?  It means nothing in either JavaScript or TwineScript (which is really just JavaScript with a light dusting of sugar).  It's not syntactical at all.

    In JavaScript (specifically): The only place where :: meant anything was in JScript, Microsoft's implementation of JavaScript (and, I think, only part of WSH or something, I don't think it was ever in IE's version of JScript).  It was used as part of some bizarre event handler syntax, separating the scriptID from the event name.

    In story formats (generally): AFAIK, the only places where :: means anything is in CSS3, where it's part the new-style pseudo-element selectors, or in SugarCube's alternate handler call syntax for macros, where it's pretty much what it says on the tin.


    Shloo wrote:

    ... So can a friendly soul show me how to create a function in a script passage ...


    This style will work in any Twine 1.x story format:

    window.FUNCTION_NAME = function (FUNCTION_PARAMETERS) {
    FUNCTION_CODE
    };
    As a very basic example:

    // Function.
    window.doTheThing = function (who) {
    return "Do the thing, " + who + "!";
    };

    // Called.
    doTheThing("Zhu Li")

    // Returns.
    Do the thing, Zhu Li!

    Shloo wrote:

    ... and then call it from a regular passage?


    I'm assuming you mean how to call it to do something useful, rather than simply how do you call a function.

    It depends somewhat on the story format and a whole lot on what you're trying to do.  For example, if all you wanted was for the function to return a string, for printing let's say, then you could call it like so: (reusing doTheThing() here)

    <<print doTheThing("Zhu Li")>>
    However, you hardly need a function for that.  So, what are you trying to do?
  • Welcome to the forums! :)

    Shloo wrote:
    Also, what does :: mean?


    On these forums, it is often used to denote a passage's title. For example, "::Start" is the passage titled "Start."

    Here is a link to one of the most popular introductions to Twine: http://www.auntiepixelante.com/twine/

    Good luck!
  • Shloo wrote:

    Also, what does :: mean?


    If you saw it within an example of TWEE notation on the forums like the following:

    :: Start
    The text displayed at the start of a story.
    [[Continue]]

    :: Continue
    The text to display when the Continue passage is shown.
    In TWEE notation the double colon at the start of a line indicates a new passage, and the text following the double colon on the same line is the new passage's title.
    In the above example there are two passages, one titled Start and the other Continue.
  • Thanks for the help - I'm always stumbling when trying to understand the basics. I had never figured out :: myself, and I got 'hello world' up and running!
    I'm not sure what exactly I want to create - I'm still just messing around with stuff. Combining 'choose-your-own-adventure' with scripting opens up for a lot of possibilities!
Sign In or Register to comment.