At this time, you will need to use map object. You will start to discover more wonderful things you can do and much more efficient coding.
A map object is just like dictionary, where you mention some "key" word and it gives back the "value" meaning. In this case, you give "up" (pun intended
), it gives back 'touchGesture(0, 40, newList(500,1000,500,700))'. So you will arrange your script into a map. Then give the map the keyword, and it will give {gest} as the script you need.
Code: Select all
gestmap = newMapFromValues(
'left', 'touchGesture(0,40, newList(100, 1400, 900, 1400))',
'right', 'touchGesture(0, 40, newList(900, 1400, 100, 1400))',
'up', 'touchGesture(0, 40, newList(500,1000,500,700))',
'down', 'touchGesture(0, 40, newList(500,700,500,1000))' );
gest = gestmap[global_navclick];
eval(gest);
newMapFromValues() is to create the map from existing value. If you need a blank map, just use newMap() and later use addMapEntry() to add the key-value pair. The whole map can be defined in single line coding, but I always prefer to typed in multiple line for easier reading.
For this case, it might seems using map doesn't shorten your code significantly. But when you need to reuse the map, you will find it that it is much easier to define the map once and use it for the rest of the flow; rather than using multiple if() to check for one thing.
For your eval usage, you don't have to assign the value to {gest} first. You can actually simply use
Then about the glovar and widget; if you need the widget to set a glovar (using action script), then the glovar triggered changes and execute the flow; it is far more efficient if you change the widget action to just use action execute flow. I use this a lot, to the point that I made a flowception just to create it. (helper flow to create action execute flow in widget).
Widget execution to a flow will pass variable {gesture}, {widget_cell_x} and {widget_cell_y} (and many others variable you can check in debug dialog). You can use this to determine the source of the widget action. Example : if your widget is 3x3 action button and your "up" is at the top center block. Then tapping this will produce gesture = "CLICK", widget_cell_x = 1, widget_cell_y = 0. Changing to this method, you can then combine the cell_x and y to get the coordinate, instead of using "up", "down", "right", "left". gesture = "CLICK" is not used here if you only tap once.
Code: Select all
point = concat(widget_cell_y, widget_cell_x);
gestmap = newMapFromValues(
'10', 'touchGesture(0,40, newList(100, 1400, 900, 1400))',
'12', 'touchGesture(0, 40, newList(900, 1400, 100, 1400))',
'01', 'touchGesture(0, 40, newList(500,1000,500,700))',
'21', 'touchGesture(0, 40, newList(500,700,500,1000))' );
eval(gestmap[point]);