View Single Post
10-22-19, 01:41 PM   #4
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
As a side note, the following line can be rewritten.
Code:
if CA_match_number ~= nil then
After the rewrite, it becomes
Code:
if CA_match_number then
The reason is that in Lua (possibly other languages as well) if/then checks seek a true answer or an answer with a value, meaning that if CA_match_number exists, it is therefore non-nil and not false.

Conversely, think about this line.
Code:
if not CA_match_number then
Specifying "not" means it must be either nil or false, and cannot be true; however, it can still have a value, in this case, the Boolean "false".

Taking it a step further, you can expand if/then to check for having a value, false, and nil.
Code:
if something then -- true or has a value, and not false and is non-nil
elseif something == false then -- specifically Boolean
elseif not something then -- non-value, non-Boolean
elseif something == nil then -- no value whatsoever
  Reply With Quote