PDA

View Full Version : Any implicit action on returning true/false/nil?



Varsuuk
May 19th, 2019, 03:54
My expectation is that it does nothing, but figured I'd ask in case my mind is about to be blown ;)

When a method (addTraitDB) is called where the return value is not explicitly checked, like so:



for _,v in pairs(DB.getChildren(nodeSource, "traits")) do
addTraitDB(nodeChar, "reference_racialtrait", v.getPath());
end


Does anything special happen based on what, if anything is returned by this method? [EDIT: like "exit the loop"]

In the current implementation, there are returns each of:
return;
return false;
(and the final all went well until the end:)
return true;

Is this is just "habit" and/or "in case in future" type coding?

Ikael
May 19th, 2019, 08:12
Nothing happens implicitly. You would need to explicitly check returned value and do something according to it.

Varsuuk
May 19th, 2019, 17:40
Ok, then they just return the true/false nil values for chuckles ;) I’ll edit my version of the method to not return anything since I do not yet have a reason to check the result either.