Watchmaker Wiki

The ultimate watch maker for Android Wear!

User Tools

Site Tools


lua

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
lua [2015/11/01 23:49]
speculatrix [Conditional Statements]
lua [2020/07/24 11:32] (current)
alexcurran1
Line 16: Line 16:
  
 (Note:  We're just starting to add Lua code examples and explanations, so it may look sparse now, but keep checking back!  Some exciting stuff is on its way!) (Note:  We're just starting to add Lua code examples and explanations, so it may look sparse now, but keep checking back!  Some exciting stuff is on its way!)
 +
  
 ===== Conditional Statements ===== ===== Conditional Statements =====
  
-Conditionals (IF-THEN-ELSE) work differently from many other programming languages. You build logical expression which is evaluatedand the result is then set as your property.+Conditional statements (IF-THEN-ELSE) work in much the same as most languages and also supports "elseif" (there are some examples below), for more information see http://www.lua.org/pil/4.3.1.html  
 + 
 + 
 +===== Conditional Value Assignment ===== 
 +These allow you to conditionally set value to a property based on some conditions, the syntax uses (IF-AND-OR).
  
 It's easy once you know this: It's easy once you know this:
Line 52: Line 57:
 ===== Strings ===== ===== Strings =====
  
-Texts can be manipulated through the [[http://www.lua.org/manual/5.3/manual.html#6.4|string library]].+Text [[http://www.lua.org/pil/2.4.html|strings]] such as "some text" can be manipulated through the string library ([[http://www.lua.org/manual/5.3/manual.html\#6.4]]). 
 + 
 +You can quote strings with double or single quotes so 'some text' is also a string.
  
 ==== Methods ==== ==== Methods ====
Line 58: Line 65:
 Upper/Lowercase a string: Upper/Lowercase a string:
  
-  string.upper({ddww}) +  string.upper('{ddww}'
-  string.lower({ddww})+  string.lower('{ddww}')
  
 Reverse a string: Reverse a string:
  
-  string.reverse({ddww})+  string.reverse('{ddww}')
  
 Shorten a string (use only first 20 chars): Shorten a string (use only first 20 chars):
Line 134: Line 141:
 You are recommended to keep Tap Action scripts shorter e.g. by running functions in the main script file, as Tap Action scripts are stored in the XML file and not the separate script file. You are recommended to keep Tap Action scripts shorter e.g. by running functions in the main script file, as Tap Action scripts are stored in the XML file and not the separate script file.
  
-===== Run Lua Function Every Second or Millisecond =====+===== Run Lua Function Every Hour, Minute, Second or Millisecond ===== 
 + 
 +    function on_hour(h)           - every hour (h = hour) 
 +    function on_minute(h, m)      - every minute (h = hour, m = minute) 
 +    function on_second(h, m, s)   - every second (h = hour, m = minute, s = second) 
 +    function on_millisecond(dt)   - every millisecond (dt = delta time)
  
 If you have some custom variables that update every millisecond, you can create an //on_millisecond(..)// function in your script file. This function will be called every millisecond. In the example below this will move points around a circle (co-ordinates stored in var_ms_posx and var_ms_posy) : If you have some custom variables that update every millisecond, you can create an //on_millisecond(..)// function in your script file. This function will be called every millisecond. In the example below this will move points around a circle (co-ordinates stored in var_ms_posx and var_ms_posy) :
Line 197: Line 209:
 WatchMaker extends the Lua commandset. Just use the wm_action() or other functions anywhere in your script or tap actions : WatchMaker extends the Lua commandset. Just use the wm_action() or other functions anywhere in your script or tap actions :
  
-    wm_action('sw_start_stop'      -- start or stop the stopwatch +    wm_action('sw_start_stop'         -- start or stop the stopwatch 
-    wm_action('sw_reset'           -- reset stopwatch +    wm_action('sw_reset'              -- reset stopwatch 
-    wm_action('m_update_weather'   -- update weather +    wm_action('m_update_weather'      -- update weather 
-    wm_action('m_task:MyTask'      -- run Tasker task 'MyTask' +    wm_action('m_task:MyTask'         -- run Tasker task 'MyTask' 
 +    wm_action('color_switch_next'     -- Color Switch: Next Color 
 +    wm_action('color_switch_prev'     -- Color Switch: Previous Color 
 +    wm_action('color_switch_select'   -- Color Switch: Select Color 
 +    wm_action('tap_launcher'          -- Launch Tap Launcher 
 +    wm_action('widget_weather'        -- Launch Weather Widget 
 +    wm_action('widget_health'         -- Launch Health Widget 
 +    wm_action('widget_calendar'       -- Launch Calendar Widget 
 +            
     wm_schedule('...'    -- schedule an animation or event (see Scheduling Animations / Functions)     wm_schedule('...'    -- schedule an animation or event (see Scheduling Animations / Functions)
     wm_unschedule_all()    -- unschedule all animations or events     wm_unschedule_all()    -- unschedule all animations or events
     wm_vibrate(d, r)       -- vibrate for duration d (milliseconds) and repeat r times      wm_vibrate(d, r)       -- vibrate for duration d (milliseconds) and repeat r times 
 +    wm_sfx('sfx_file'    -- play MP3 file with name sfx_file.mp3 (needs to be in /BeautifulWatches/sfx) - supported watches with speaker only
     wm_transition('...'  -- run a transition (see Transitions)     wm_transition('...'  -- run a transition (see Transitions)
 +    wm_anim_set('layerName', 'anim_in', 'Typewriter"    -- set animation in for 'layerName' to Typewriter
 +    wm_anim_set('layerName', 'dur_in', 1.0)     -- set duration in for 'layerName' to 1.0 (or use -1 for default)
 +    wm_anim_start('layerName'   -- start animation on 'layerName'
     wm_tag('...'         -- ONLY use for dynamic variables otherwise will break     wm_tag('...'         -- ONLY use for dynamic variables otherwise will break
                                 return a value of a WatchMaker tag, e.g. wm_tag("{c"..var_myvar.."bp}")                                 return a value of a WatchMaker tag, e.g. wm_tag("{c"..var_myvar.."bp}")
Line 239: Line 262:
     end     end
          
-    -- t = time == how much time has to pass for the tweening to complete+    -- t = time == running time. How much time has passed *right now*
     -- b = begin == starting property value     -- b = begin == starting property value
     -- c = change == ending - beginning     -- c = change == ending - beginning
-    -- d = duration == running time. How much time has passed *right now*+    -- d = duration == how much time has to pass for the tweening to complete
  
 ===== Transitions ===== ===== Transitions =====
lua.1446418173.txt.gz · Last modified: 2015/11/01 23:49 by speculatrix