Chapter 8. Math (and Gambling)

Dust off your dunce cap. This chapter covers mathematical, geometric, and trigonometric operations for both the mathematically adept and the numerically challenged. If you are one of the latter, at least you’ll enjoy the section on gambling at the end of the chapter. Refer to Chapter 5, for details on data type conversion, expression evaluation, logical operators, and comparison operators. See Chapter 6, for an introduction to rects and points and mathematical operations with lists. Refer to Chapter 5, Coordinates, Alignment, and Registration Points, in Director in a Nutshell for more details on rects, points, coordinate systems, and alignment of sprites on the Stage.

Tip

The cross-platform MathXtras from Maxwell Technologies (http://www.maxwell.com/mathxtras) provide these math-related functions: customizable on-screen calculator, scrolling odometer-style counter, equation editor, graphing functions, spreadsheet tables, and even sliders and speedometers.

Arithmetic Operators

Director supports the usual complement of arithmetic operators, as shown in Table 8-1. Operations with a higher precedence are performed first. Operations with the same precedence are performed left to right. The order of evaluation can be overridden with parentheses. Refer also to Table 5-7 and Table 5-8, which detail the precedence of comparison and Boolean operators. If one or both operands in an expression are floats, the result is a float. If both operands are integers, the result ...

Get Lingo in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.