Thread Tools Display Modes
Prev Previous Post   Next Post Next
05/09/14, 06:05 AM   #3
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
When we define just 2 forms in pattern, it means that first form is for num = 1 and second form for anything else. So, this pattern will have the same output as in example above:

Lua Code:
  1. pattern = "I have sold <<1>> <<1[item/items]>>."


We can modify pattern even further using the $d variable:
Lua Code:
  1. pattern = "I have sold <<1[$d item/$d items]>>"
$d will get replaced with actual value of argument, so output will be the same as in both examples above.


Also we can leave empty any of the forms, so there will be no return value. Good example is time format:
Lua Code:
  1. pattern = "Remaining time: 1[/1 minute and /$d minutes and ]>><<2[1 second/$d seconds]>>"
  2.  
  3. msg = zo_strformat(pattern, min, sec)

As we do not have defined form for zero value for minutes, output will be:
if min = 0, sec = 1
msg = "Remaining time: 1 second"

if min = 0, sec = 5
msg = "Remaining time: 5 seconds"

if min = 5, sec = 0
msg = "Remaining time: 5 minutes and 0 seconds"

Last edited by Garkin : 05/10/14 at 08:02 PM.
  Reply With Quote
 

ESOUI » Developer Discussions » Tutorials & Other Helpful Info » Singular & plural form using the zo_strformat() function


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off