lua
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
lua [2015/03/20 09:48] – [WatchMaker Lua API] alex_curran | lua [2017/07/05 10:26] – alex_curran | ||
---|---|---|---|
Line 16: | Line 16: | ||
(Note: | (Note: | ||
+ | |||
===== Conditional Statements ===== | ===== Conditional Statements ===== | ||
- | Conditionals | + | Conditional statements |
+ | |||
+ | |||
+ | ===== Conditional Value Assignment ===== | ||
+ | These allow you to conditionally set a 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 25: | Line 30: | ||
^ IF < | ^ IF < | ||
- | Simple | + | A simple |
({dm} % 2 == 0) and ' | ({dm} % 2 == 0) and ' | ||
- | More complex example: | + | A more complex example: |
({dh} < 11) and ' | ({dh} < 11) and ' | ||
| | ||
- | Note the parentheses. | + | Note the parentheses. |
+ | |||
+ | Here's another example of why it's a good idea to add parentheses: | ||
({dh} > 23 or {dh} < 1) and ' | ({dh} > 23 or {dh} < 1) and ' | ||
Line 50: | Line 57: | ||
===== Strings ===== | ===== Strings ===== | ||
- | Texts can be manipulated through the [[http:// | + | Text [[http:// |
+ | |||
+ | You can quote strings with double or single quotes so 'some text' is also a string. | ||
==== Methods ==== | ==== Methods ==== | ||
Line 56: | Line 65: | ||
Upper/ | Upper/ | ||
- | 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 195: | Line 204: | ||
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(' | + | wm_action(' |
- | wm_action(' | + | wm_action(' |
- | wm_action(' | + | wm_action(' |
- | wm_action(' | + | wm_action(' |
+ | wm_action(' | ||
+ | wm_action(' | ||
+ | wm_action(' | ||
wm_schedule(' | wm_schedule(' | ||
wm_unschedule_all() | wm_unschedule_all() | ||
+ | wm_vibrate(d, | ||
+ | wm_transition(' | ||
+ | wm_tag(' | ||
+ | return a value of a WatchMaker tag, e.g. wm_tag(" | ||
is_bright | is_bright | ||
Line 224: | Line 240: | ||
You can write your own tweening function like this : | You can write your own tweening function like this : | ||
- | function linear_myversion(t, b, c, d) | + | function linear_myversion(d, b, c, t) |
return c * t / d + b | return c * t / d + b | ||
end | end | ||
| | ||
- | function inQuad_myversion(t, b, c, d) | + | function inQuad_myversion(d, b, c, t) |
t = t / d | t = t / d | ||
return c * math.pow(t, 2) + b | return c * math.pow(t, 2) + b | ||
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 ===== | ||
+ | |||
+ | From WatchMaker 3.6, you can run over 45 transitions when switching between screens on a watchface. | ||
+ | |||
+ | wm_transition(' | ||
+ | This will start a transition to the next screen. | ||
+ | |||
+ | Free Transitions Watch: http:// | ||
+ | |||
+ | See video of all transitions here: http:// | ||
+ | |||
+ | You should not use wm_transition for bright / dim animations - instead set the transition directly in WatchMaker watch editor. | ||
+ | |||
+ | The full list of transitions is shown below (you can add spaces if needed or use lower-case) : | ||
+ | None, Random, | ||
+ | FlipFromLeft, | ||
+ | ScrollFromLeft, | ||
+ | SlideFromLeft, | ||
+ | CrossHatch, CrossZoom, CubeFromLeft, | ||
+ | Dreamy, DreamyZoom, Fade, | ||
+ | FoldFromLeft, | ||
+ | GlitchDisplace, | ||
+ | SquareSwipe, | ||
+ | HSVFade, LinearBlur, RandomSquares, | ||
+ | PageCurl, Radial, PowerDisformation, | ||
+ | FadeBlack, FadeWhite, CircleOpen, | ||
+ | |||
===== Learn More ===== | ===== Learn More ===== | ||
You can learn more about how to use Lua from the many use cases listed on our [[tips: | You can learn more about how to use Lua from the many use cases listed on our [[tips: |
lua.txt · Last modified: 2020/07/24 09:32 by alexcurran1