I'm watching some tutorials and they use elseif, and I don't know what it is, because they don't explain it, and I can't find tutorials that explain what is elseif used for.
The simple answer is that the else
block will run if no other blocks ran and a elseif
block will be evaluated if the previous did not run.
Now some examples ........
using else
local run = true if run then print('runs only if truthy') else print('runs if the above did not run') end
using elseif
local run = true local run2 = true local run3 = true if run then print('run first') elseif run2 then print('the above did not run. run must be falsy') elseif run3 then print('you can chain as many as you want but only the first one that evaluate to true will run') else print('none of the above ran') end
The above are just some testing setups you can run and turn the variable from true to false.
Also take a look at how Lua treats type as either true or false her
I hope this helps. Please comment if you have any other questions about this code.