tmedwards / sugarcube-2

SugarCube is a free (gratis and libre) story format for Twine/Twee.
https://www.motoslave.net/sugarcube/2/
BSD 2-Clause "Simplified" License
177 stars 41 forks source link

RFE: option to <<textbox>> for actions rather than a passage #44

Closed boyland closed 4 years ago

boyland commented 4 years ago

I've found it limiting to have the only way to handle a CR on a textbox is to go to a new passage. I created my own version <<textboxlink>> that silently expands its payload when CR is pressed. I could do a pull-request, if you'd like. Otherwise, the only real difference is changing

// If Return/Enter is pressed, set the variable and, optionally, forward to another passage.
if (ev.which === 13) { // 13 is Return/Enter
    ev.preventDefault();
    State.setVar(varName, this.value);

    if (passage != null) { // lazy equality for null
        Engine.play(passage);
    }
}

to

// If Return/Enter is pressed, set the variable and, perform link
if (ev.which === 13) { // 13 is Return/Enter
    ev.preventDefault();
    State.setVar(varName, this.value); // redundant?
    Wikifier.wikifyEval(contents);
}

where contents is set to this.payload[0].contents.trim() in the outer scope.

tmedwards commented 4 years ago

I think you're forgetting that <<textbox>> is not a container macro—i.e., it has no contents.

boyland commented 4 years ago

Well, that's why my macro is called <<textboxlink>> and it is a container macro. A clunky name, but gets across the idea, I hope.

tmedwards commented 4 years ago

Ah, my mistake. I thought you wanted to modify <<textbox>> itself.

There's already an add-on macro, <<textboxplus>>, that's a containerized version of <<textbox>>, which also doesn't drop the ability to forward as yours does.

I prefer modifications to core macros as add-ons, so I think we'll leave it as that.

boyland commented 4 years ago

Thanks. The add-on looks like exactly what I need. Is it obvious how to use an add-on? Or is it used the same way that I defined my custom-macro: copy JavaScript code into my story?

tmedwards commented 4 years ago

You copy the given JavaScript into the JavaScript section of your project. Add-ons generally come with documentation, instructions and usage, but <<textboxplus>> was a quick Gist for a request.