Game Development Reference
In-Depth Information
disable it to not handle them. In the code sample that follows, we check if the variable fDisable is
true or not. If it is, we simply return from the code without executing the remainder of the code that
follows.
function someFunction()
if fDisable ==true then return end
-- The code following is what you want to do if the code were to run
end
By just returning from the function, we do not in effect execute the code of the function, which is
as good as disabling the function temporarily. In contrast to this, you might have to remove event
handlers and then set them up again, which is more cumbersome than this simple flag method.
and and or work. Lua gives you the ability to not use
or is widely used in Lua is to assign default values to variables, like so:
=somevalue
aVal=defaultValue
=somevalue or defaultValue
Table 4-1 gives a quick overview of how and and or work.
Table 4-1. Boolean Operations
Boolean Operation
Value 1
Value 2
Operator
Result
print(5)
5
-
-
5
print(5 and 6)
and
5
6
6
print(5 or 6)
or
5
6
5
print(nil and 6)
nil
and
nil
6
print(nil or 6)
nil
or
6
6
print(5 and nil)
nil
and
nil
5
print(5 or nil)
nil
or
5
5
Summary
If you are serious about game development, you need to understand math. There are a lot of
functions that can help you as a developer. You can check for collisions; check for intersections
of lines, rectangles, and circles; and determine the angle and distance between two objects.
Many Lua math functions are valid across frameworks, and there are some frameworks that have
integrated math libraries. We have a lot of these generic functions in Chapter 7 and in Chapter 13,
which discusses third-party libraries, we'll create a math vector library, which will be useful with
frameworks that do not have vector functions.
 
Search WWH ::




Custom Search