Game Development Reference
In-Depth Information
Chapter 7
Tips and Tricks
The dilemma that many developers face is, as the old saying goes, there are many ways to skin a
cat. In simple terms, while there are many ways to achieve an outcome, many developers face the
issue of how to and where to start. This chapter will help you with those starting points. It will offer
the tips and tricks that can be applied across most of the frameworks. The main differences to note
are the native display objects as used by the frameworks and some quirks associated with those.
Generic Lua Functions
This section addresses some generic functions that help developers and can be used across all
frameworks. Most of these are related to tables for storage, retrieval, and indexing, and math
relevant to game development.
Using the printf Function
Lua has a print function, but it does not allow for formatted output like the C printf does. It is
always nice to have outputs that are formatted and read like a sentence, as opposed to pieces of
information stuck together. " There are 5 boys and 4 girls in the Math class " rather than " Boys:5
Girls: 3, Class: Math " which could have been outputted using the code
print("Boys:", boys, "Girls:", girls, "Class:", className)
The printf function is quite simple, and can be used as follows:
function printf(format, ...)
print(string.format(format, ...))
end
97
 
Search WWH ::




Custom Search