Watchmaker Wiki

The ultimate watch maker for Android Wear!

User Tools

Site Tools


tips:tapcolor

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
tips:tapcolor [2015/03/30 21:10]
jt3
tips:tapcolor [2015/04/24 07:16] (current)
jt3 [Explanation]
Line 1: Line 1:
 ====== Changing Color Through Tap Action ====== ====== Changing Color Through Tap Action ======
  
-A feature that's becoming more and more common, especially with paid watches that can't be edited, is the ability to change the color of an item or items on your watch face via tap action.  This tutorial will explain the most efficient method for doing this.  We'll be using arrays, so you're going to need (at least) version 3.4 of WatchMaker to pull this off.+A feature that's becoming more and more common, especially with paid watches that can't be edited, is the ability to change the color of an item or items on your watch face via tap action.  This tutorial will explain the most efficient method for doing this.  We'll be using arrays, so you're going to need version 3.4 (or higher) of WatchMaker to pull this off.
  
-===== Examples =====+===== Example =====
  
 ==== Main Script ==== ==== Main Script ====
Line 19: Line 19:
  
  
-==== Color Field of Object ====+==== Color Field of Object(s) ====
    var_color1[var_clrnum]    var_color1[var_clrnum]
 ==== Tap Action ==== ==== Tap Action ====
Line 28: Line 28:
 We start in the main script by initializing our variables.  we do this to avoid having a variable set to NULL, which is always a good idea.  The two variables we care about are "var_clrnum," which is color selection, and "var_color1" which is the color itself.  If you were wanting to have themes, where each theme has multiple colors that go together, you'd simply add a var_color2, var_color3, etc. in the same manner.  Everything else would stay the same, and you'd use the same, single, var_clrnum, to set the color on everything. We start in the main script by initializing our variables.  we do this to avoid having a variable set to NULL, which is always a good idea.  The two variables we care about are "var_clrnum," which is color selection, and "var_color1" which is the color itself.  If you were wanting to have themes, where each theme has multiple colors that go together, you'd simply add a var_color2, var_color3, etc. in the same manner.  Everything else would stay the same, and you'd use the same, single, var_clrnum, to set the color on everything.
  
-Let's take a closer look at that "Var_color1."  This is called an array (or table).  What we've done here is set 7 separate values to the same variable, each being a color in hexadecimal format.  These seven values are comma-separated, and since they're strings, each must have a string identifier.  In this case, we used apostrophes.  In an array, we determine which value we want like this:  var_color1[1], var_color1[2], and so on.  So, all we need to do to change the color is change the number in the brackets.  That's where var_clrnum comes in.+Let's take a closer look at that "var_color1."  This is called an array (or table).  What we've done here is set 7 separate values to the same variable, each being a color in hexadecimal format.  These seven values are comma-separated, and since they're strings, each must have a string identifier.  In this case, we used apostrophes as string identifiers, but you can use quotes if you're one of **those** people :-P.  Just be consistent throughout each array.  Don't mix string identifiers, or things can get ugly. 
 + 
 +Since, in an array, a variable can have multiple values, we determine which value we want like this:  var_color1[1], var_color1[2], and so on.  So, all we need to do to change the color is change the number in the brackets.  That's where var_clrnum comes in.
  
 In the script, we set up a function that acts as a toggle.  Each time we call the function, which we'll do via tap action, we increase the value of var_clrnum by one.  When we reach the maximum (the number of entries in our array) value of 7, we simply set it back to 1.  That way, var_clrnum is never a number that does not represent a value in var_color1. In the script, we set up a function that acts as a toggle.  Each time we call the function, which we'll do via tap action, we increase the value of var_clrnum by one.  When we reach the maximum (the number of entries in our array) value of 7, we simply set it back to 1.  That way, var_clrnum is never a number that does not represent a value in var_color1.
Line 37: Line 39:
  
 Add or remove colors by simply adding or removing colors in the var_color1 array, and changing the function to ensure that the maximum number matches the number of colors.  It is important that if you added a var_color2, var_color3, etc., that they all have the same number of entries as var_color1.  Var_clrnum should never be allowed to have a value that doesn't map to a color in any array that uses it, or you could end up with errors. (Remember that whole "Null" thing we were trying to avoid?) Add or remove colors by simply adding or removing colors in the var_color1 array, and changing the function to ensure that the maximum number matches the number of colors.  It is important that if you added a var_color2, var_color3, etc., that they all have the same number of entries as var_color1.  Var_clrnum should never be allowed to have a value that doesn't map to a color in any array that uses it, or you could end up with errors. (Remember that whole "Null" thing we were trying to avoid?)
 +
 +One last thing:  Capitalization and auto-correct can get you into trouble.  You'll notice there is no capitalization in any of the example code (except where it says "Script:" but I already pointed out that that's added by WatchMaker, and not actually part of the typed code).  That's because you have to be VERY careful with capitalization in any coding language.  There's nothing wrong with it, but you'll find that most coders only use it for clarification, and avoid it otherwise.  For example, a variable name like VarToMakeThingsEasierToRead kind of needs capitalization (or at least a good slap upside the head to the programmer that insists on using such long freaking variable names). Remember, Var_clrnum is not the same as var_clrnum, when coding.  If you're having issues, check to make sure that something didn't get capitalized or auto-corrected against your will.
  
  
  
tips/tapcolor.1427742629.txt.gz · Last modified: 2015/03/30 21:10 by jt3