Quantcast
Channel: Help! with 2.0 - Twine Forum
Viewing all articles
Browse latest Browse all 1844

Pluralize widget

$
0
0
I'm using Sugarcube 2.12 to try to make a pluralize widget.

Use cases:
<<pluralize 2 "hour">> should return "2 hours"
<<pluralize 1 "item">> should return "1 item"
<<pluralize 3 "antenna" "e">> should return "3 antennae"

Here's what I've tried:
<<widget "pluralize">>
<<set _num = $args[0]>>
<<set _plu = $args[1]>>
<<if _num neq 1>>
  <<if $args[2]>>
    <<set _plu = _plu + $args[2]>>
  <<else>>
    <<set _plu = _plu + "s">>
  <</if>>
<</if>

<<= _num>>
<<= _plu>>
<<endwidget>>

However, weirdly, only the _plu is showing in all cases. The _num is never shown. At all.

But if I add
<<set _num += "">>
right before it's printed (on the blank line above), it's showing.

So I guess the widget is "working", (and now: Ryan Reynolds) but why?

Viewing all articles
Browse latest Browse all 1844

Trending Articles