Let's say I want to have a entity with a long onUpdate function to be called every x ticks.
Could I have that method in a seperate file (ex: EntityMobFile.lua) such that all code related to this entity is eaisly found there and not inside a miles long control.lua?
I assume there must be a simple way to get some organization and sepperation when creating a mod with several entities
psudo code to illustrate my thinking:
int y = 0
game.onevent(defines.events.ontick, function(event)
{
y++
if (x %y )
{
EntityMobFile.onUpdate(someData)
}
}
On tick call method in another file
Re: On tick call method in another file
control.lua
mod.lua
Code: Select all
defines = require "defines"
local mod = require "mod"
script.on_event(defines.events.on_tick, function(event)
if event.tick % 60 == 0 then -- every second
return
end
mod:update(event)
end)
Code: Select all
local mod = {}
mod.update = function(self, event)
-- do something here
end
return mod