Game Development Reference
In-Depth Information
Fixed Parameters
The default convention for passing parameters to a function is using fixed parameters. These tell
the function how many parameters there will be and the order of the parameters. When using fixed
parameters, you know what to expect from the function, and based on the values of the parameters
passed, you can take appropriate action.
function listParams(one, two, three)
print("We got :", one, two, three)
if one=="one" then
print("Something")
else
print("Nothing")
end
print("We got :")
for i, j in pairs(arrTable) do
print("", i, j)
end
end
Variable Named Parameters
You can use variable named parameters when you do not know what is passed, but you want to
check for certain parameters. This is also a table like in the example above, but instead of having
table items, it has named items, which can be referenced by name rather than an index.
function namedArrayParams(arrTable)
if arrTable.debug == true then
print("We are now in Debug Mode")
else
print("We are not in Debug Mode")
end
if arrTable.color then
print("We got the color as ", arrTable.color)
else
print("We shall use the default color")
end
end
 
Search WWH ::




Custom Search