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

Add a `<<select>>` macro #241

Open tmedwards opened 1 year ago

tmedwards commented 1 year ago

What it says on the tin.

<<select [optional_args]>>
    /*
        Links (<a> or <button>) and, optionally, descriptive text.
    */
<<onselect>>
    /*
        Code to run if the player selects a link.
    */
<<ontimeout>>
    /*
        Code to run if the `time` option is specified and the player fails to select a link in time.
    */
<</select>>

Arguments

Optional

Events

Notes

Ideas

hituro commented 1 year ago

It would be great if it also fires an event when the timer runs out, passing the ID of the QTE that generated it

SjoerdHekking commented 1 year ago

Also, a possibility to pause the timer would be nice, reasoning an author could make an "extra time" button or some "easy" game mode!

MalifaciousGames commented 1 year ago

It'd be nice to have an easy way to disable the timer alltogether (maybe if the time value is false ?).

I can see qte timing being offered as a setting, going from fast to entirely disabled.

<<qte `(3* settings.qteSpeed)+'s'`>>...<</qte>>
tmedwards commented 1 year ago

Made some edits to the issue.

@hituro @SjoerdHekking @MalifaciousGames

tmedwards commented 1 year ago

It would be great if it also fires an event when the timer runs out, passing the ID of the QTE that generated it

The ID is optional, so that's a wash. The event target will be the wrapper element though, which is better anyway.

david-donachie commented 1 year ago

It would be great if it also fires an event when the timer runs out, passing the ID of the QTE that generated it

The ID is optional, so that's a wash. The event target will be the wrapper element though, which is better anyway.

Yeah, that makes sense

tmedwards commented 1 year ago

I'm thinking about using a button to unlock the content and timer rather than by scrolling into view. This would almost certainly be better in situations where there's considerable text before the QTE that the player may want or need to read—for the QTE to make sense.

tmedwards commented 1 year ago

Updates to the OP. The macro will be more generally useful.

Might change the name since Sleepy has a <<select>> macro. Dunno.

greyelf commented 1 year ago

Might change the name since Sleepy has a <<select>>

Maybe <<action>> as a potential name replacement.

ChapelR commented 1 year ago

Select doesn't seem like the right word to me, but I can't think of anything better, either. Not helpful, I know, but I'll think about it.

david-donachie commented 1 year ago

Name suggestions, some variant on "time limit"

tmedwards commented 1 year ago

Maybe <<action>> as a potential name replacement.

Too close to <<actions>>. I don't like one of the alternates I came up with, <<choose>>, for a similar reason—to close to <<choice>>.

I need to formally deprecate those two, so I can reuse the names someday.

 

Name suggestions, some variant on "time limit"

The current intent is a generic selection macro, so time-/duration-based names are a bust.

It still has a time option, so it can be a QTE, but that's not the sole thrust anymore.

tmedwards commented 1 year ago

Select doesn't seem like the right word to me, but I can't think of anything better, either. Not helpful, I know, but I'll think about it.

Please do. 🙏🏻

I hit the thesaurus already, but that was a bust. Then again, I was probably thinking too narrowly.

david-donachie commented 1 year ago

The current intent is a generic selection macro, so time-/duration-based names are a bust.

It still has a time option, so it can be a QTE, but that's not the sole thrust anymore.

Looking again, then, maybe right name is <<choices>>, as analogue to the existing <<actions>>.

Contents could then be links, <<link>>, buttons, <<button>> and <<choice>>. Rename <<onselect>> to something like <<any>> or <<after>> because it runs in addition to the whichever choice was selected.

Not to feature-creep, but if the same worked with <<radiobutton>> and <<checkbox>> you'd have also solved one of the most requested help features that pushes people to JS event handlers, namely the "How do I have something happen immediately when any one of these radiobuttons is chosen"

MalifaciousGames commented 1 year ago

I agree with Hituro in the sense that this feels like two macros in a trenchcoat:

It is true that limiting the qte target to being a link feels arbitrary, and it'd be convenient to be able to attach a click listener to any element.

But in this situation, a macro which could listen for any event type would solve more issues and have broader uses.

<<listen>>

  The answer is:
  <<numberbox '$var' 0>>

<<when 'change'>>

  <<if $var === 15>>
    <<goto 'GoodJob'>>
  <</if>>

<</listen>>
tmedwards commented 1 year ago

Looking again, then, maybe right name is <<choices>>, as analogue to the existing <<actions>>.

That's not happening for exactly the same reason I gave to Greyelf. It's too close to the name of an existing macro. Simply adding or removing an "s" is not sufficient.

I should have hard deprecated those two miserable things ages ago. Missed opportunity that. /sigh

 

Contents could then be links, <<link>>, buttons, <<button>> and <<choice>>.

The active contents, as noted above, are <a> & <button> elements, regardless of how they're created.

 

Rename <<onselect>> to something like <<any>> or <<after>> because it runs in addition to the whichever choice was selected.

I'll be sticking with the <<on…>> naming. I'm satisfied with that.

 

Not to feature-creep, but if the same worked with <<radiobutton>> and <<checkbox>> you'd have also solved one of the most requested help features that pushes people to JS event handlers, namely the "How do I have something happen immediately when any one of these radiobuttons is chosen"

That's not really feasible in v2 for a few reasons:

My personal preference is targeted applications built into macros that need it rather than attempting to have some generic catch all that's not much better than using a little JavaScript. E.g., making <<textbox>> and <<radiobutton>> containers.

tmedwards commented 1 year ago

Maybe I should just suck it up and add an event wrapper macro as a stopgap in v2 until I can fix the core macro set in v3.

I just don't want to get into a situation where people are doing dumb shit cargo culting by combining macros that don't need to be combined, thus causing a mess.

Feh. 🤦🏻 Going to drive myself crazy with this.

greyelf commented 1 year ago

Another potential issue with the name <<select>> is the fact that HTML has a <select> element that behaves nothing like this macro.

tmedwards commented 1 year ago

The name's not going to be <<select>>, I just had to choose something after the scope changed.