Capture the Trig Function from an Option Menu Button

Jim Hurley jhurley0305 at sbcglobal.net
Sun Dec 9 23:47:10 EST 2012


Hi Mark

I can recall one case where Do was the perfect solution for me.
It was a tutorial to help students understand the physics of the rainbow.
It provided them with a mini-programing language, that allowed them to control how a ray of light might interact with a drop of water.
They would write a script for the ray they wanted to consider. For example;

startRayAt d
refractionAirToWater
crossDrop
reflection
crossDrop
refractionWaterToAir
exitRay

This ray is refracted into the drop at the initial face, crosses the drop then to be reflected off of the back surface, and is eventually reflected and refracted back into the air.
This would be typical path for rays responsible for the primary rainbow.

This student script is written into a field called "program" and is handled by: 

repeat with k = 1 to number of lines in field "program"
      do line k of field "program"
end repeat

Nothing could be simpler or less error prone. Speed was not an issue. 
The alternative would have been to write a conditional for each of the commands in the 6 word vocabulary. 
What a nuisance. Do is obviously the solution in this case.

In Roger Guay's problem it is a two step process, (1) get the value for the trig function and then (2) a statement, and them combine them into a printed statement.
This process  might be easier to read, and simpler to execute as a Switch/Case solution.


Jim
----------------------
Jim-

> Sunday, December 9, 2012, 12:36:07 PM, you wrote:
>  In many cases it will boil down to taste, and I will grant you
>  that that is no small issue. It is a good part of what makes coding
>  satisfying.

Good points all. I usually try to avoid do whenever I can due to its
inherent slowness and the need to overthink the syntax... I'm never
really sure whether I can use a variable or whether I have to quote it
or even embed quote chars to get it to evaluate properly.

Luckily there's no "one size fits all" formula in xtalk and there are
many ways to get to any desired goal.

-- 
-Mark Wieder
 
mwieder at ahsoftware.net





More information about the use-livecode mailing list