Greets all,
This is a bit of a thread resurrection, sorry about that.
I'm trying to teach myself lua scripting (I'm a sociology grad student by trade, so this isn't my area of expertise). As I was trying implement the bit of scripting Nick provided into my system for the IRE game I play, I ran into a little tidbit that I just couldn't wrap my mind around.
-- find an affliction we have, and try to cure it
function do_cure ()
-- can't eat more if just ate, or can't eat food
if eating or
afflicted_by.food or
afflicted_by.anorexia then
return
end -- if can't do it yet
-- find most urgent one to cure
etc. etc.
end -- function do_cure
The part in bold is throwing me off a bit. As I understand it, the "or" operator returns the first argument if it is not false and the second argument if the first is false. This is all fine and all, but I don't understand how it's behaving with the "if . . . then" control.
As I understand it, if . . . then statements operate off of a logical condition. If the condition is met, then the "then" action is carried out. If it is not met, then the "then" part won't be carried out. When I look at that bolded chunk, it seems to me that something is missing, shouldn't we be giving it some sort of logical condition like:
if eating = true then X
elseif afflicted_by.food then X
etc. (I come from a vbscript backgroud)
Why does simply returning the value of one of those three arguments (eating, afflicted_by.food, afflicted_by.anorexia) lead to the proper conditions for the "then" statement to be carried out.
(Looking back, that was a very verbose post, let me know if anything is unclear.) |