View Single Post
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