Page 1 of 1

TIR 0 = truthy

Posted: Fri Oct 07, 2016 3:30 pm
by aubergine18
Today I remembered: In Lua, number 0 is a truthy value (only `nil` and `false` are falsey, everything else, including empty string, is truthy).

Code: Select all

if 0 then
  game.print('truthy') -- prints 'truthy' to console
end
So if you're using % in an on_tick event handler, bear that in mind... you can't just use "if not game.tick % 180 then", you have to do something like:

Code: Select all

script.on_event( defines.events.on_tick, function()
  if game.tick % 180 == 0 then
      -- do something every 180 ticks
  end
end

Re: TIR 0 = truthy

Posted: Fri Oct 07, 2016 3:43 pm
by Klonan
Its slightly easier if you do

Code: Select all

if game.tick % 180 ~= 0 then return end
So you don't have to maintain your indent through the whole function