greatguys Posted March 17, 2015 Share Posted March 17, 2015 I've been trying to add an adjustable digestion timer for the lure plant, but can only get it to work on a static timer. With what I have it at now, it gives a scheduler error.My config options in modinfo.luaconfiguration_options ={ { name = "timer", label = "Digestion Time", options = { {description = "20 Secs.", data = "20"}, {description = "1 Minute", data = "60"}, {description = "2 Minutes", data = "120"}, {description = "3 Minutes", data = "180"}, {description = "4 Minutes", data = "240"}, {description = "5 Minutes", data = "300"}, {description = "10 Minutes", data = "600"}, {description = "15 Minutes", data = "900"}, {description = "20 Minutes", data = "1200"}, {description = "25 Minutes", data = "1500"}, {description = "30 Minutes", data = "1800"}, }, default = "20", },} My modmain.luaPrefabs = { prefab("lureplant"),}if GetModConfigData("timer")==20 then local newdigest = 20elseif GetModConfigData("timer")==60 then local newdigest = 60elseif GetModConfigData("timer")==120 then local newdigest = 120elseif GetModConfigData("timer")==180 then local newdigest = 180elseif GetModConfigData("timer")==240 then local newdigest = 240elseif GetModConfigData("timer")==300 then local newdigest = 300elseif GetModConfigData("timer")==600 then local newdigest = 600elseif GetModConfigData("timer")==900 then local newdigest = 900elseif GetModConfigData("timer")==1200 then local newdigest = 1200elseif GetModConfigData("timer")==1500 then local newdigest = 1500elseif GetModConfigData("timer")==1800 then local newdigest = 1800endlocal function Digest(prefab) prefab.components.digester.digesttime = newdigestend AddPrefabPostInit("lureplant", Digest) And the error log[00:04:14]: [string "scripts/scheduler.lua"]:291: attempt to perform arithmetic on local 'dt' (a nil value)LUA ERROR stack traceback:scripts/scheduler.lua:291 in (method) GetListForTimeFromNow (Lua) <289-302>self =running = table: 0CC20BF0waitingfortick = table: 0CC20BC8tasks = table: 0CC20B50waking = table: 0D89F480attime = table: 0CC20C68hibernating = table: 0CC20C40dt = nilnowtick = 2283scripts/scheduler.lua:306 in (method) ExecutePeriodic (Lua) <304-310>self =running = table: 0CC20BF0waitingfortick = table: 0CC20BC8tasks = table: 0CC20B50waking = table: 0D89F480attime = table: 0CC20C68hibernating = table: 0CC20C40period = nilfn = function - scripts/components/digester.lua:8limit = nilinitialdelay = nilid = 112463arg = nilperiodic = *** failed to evaluate ***scripts/entityscript.lua:993 in (method) DoPeriodicTask (Lua) <990-1002>self (valid:true) =GUID = 112463inlimbo = falsebrain = --brain--sleep time: 0.00Priority - READY ()>0.00>ControlMinions - READY ()>0.00OnLongUpdate = function - scripts/prefabs/lureplant.lua:214AnimState = AnimState (0C6A5538)task = PERIODIC 112463: 1.000000Network = Network (0C6A45B8)pendingtasks = table: 153D85A0sg = sg="lureplant", state="idlein", time=45.23, tags = "hiding,idle,vine,"spawntime = 30.866668276489Transform = Transform (0C6A4778)actionreplica = table: 0D87A038event_listening = table: 36AD7908actioncomponents = table: 0D87D170entity = Entity (1D24B418)prefab = lureplantOnEntitySleep = function - scripts/prefabs/lureplant.lua:255OnSave = function - scripts/prefabs/lureplant.lua:208children = table: 14B76D00OnLoad = function - scripts/prefabs/lureplant.lua:200lurefn = function - scripts/prefabs/lureplant.lua:164MiniMapEntity = MiniMapEntity (0C6A5638)event_listeners = table: 36AD9500OnEntityWake = function - scripts/prefabs/lureplant.lua:250ListenForWinter = PERIODIC 112463: 30.000000name = Meat Bulbpersists = truebrainfn = table: 1D803BC0replica = table: 0D878850SoundEmitter = SoundEmitter (0C6A4678)components = table: 0D876438Physics = Physics (0C6A3F78)time = nilfn = function - scripts/components/digester.lua:8initialdelay = nilarg = nilscripts/components/digester.lua:8 in (local) fn (Lua) <6-10>scripts/entityscript.lua:880 in (method) PushEvent (Lua) <874-897>self (valid:true) =GUID = 112463inlimbo = falsebrain = --brain--sleep time: 0.00Priority - READY ()>0.00>ControlMinions - READY ()>0.00OnLongUpdate = function - scripts/prefabs/lureplant.lua:214AnimState = AnimState (0C6A5538)task = PERIODIC 112463: 1.000000Network = Network (0C6A45B8)pendingtasks = table: 153D85A0sg = sg="lureplant", state="idlein", time=45.23, tags = "hiding,idle,vine,"spawntime = 30.866668276489Transform = Transform (0C6A4778)actionreplica = table: 0D87A038event_listening = table: 36AD7908actioncomponents = table: 0D87D170entity = Entity (1D24B418)prefab = lureplantOnEntitySleep = function - scripts/prefabs/lureplant.lua:255OnSave = function - scripts/prefabs/lureplant.lua:208children = table: 14B76D00OnLoad = function - scripts/prefabs/lureplant.lua:200lurefn = function - scripts/prefabs/lureplant.lua:164MiniMapEntity = MiniMapEntity (0C6A5638)event_listeners = table: 36AD9500OnEntityWake = function - scripts/prefabs/lureplant.lua:250ListenForWinter = PERIODIC 112463: 30.000000name = Meat Bulbpersists = truebrainfn = table: 1D803BC0replica = table: 0D878850SoundEmitter = SoundEmitter (0C6A4678)components = table: 0D876438Physics = Physics (0C6A3F78)event =[00:04:14]: SCRIPT ERROR! Showing error screen[00:04:16]: QueryServerComplete no callback[00:04:16]: QueryServerComplete no callback[00:04:20]: Force aborting... I'm very new to this and any help is greatly appreciated Link to comment Share on other sites More sharing options...
greatguys Posted March 17, 2015 Author Share Posted March 17, 2015 I cut down the code in modmain.lua, and print returns the desired value, but it's still digesting at the default 20 seconds. This is the update modmain.lualocal function Digestionist(prefab) prefab.newdigest = GetModConfigData("timer") prefab.components.digester.digesttime = prefab.newdigest print(prefab.components.digester.digesttime)endAddPrefabPostInit("lureplant", Digestionist) Link to comment Share on other sites More sharing options...
greatguys Posted March 17, 2015 Author Share Posted March 17, 2015 And forgot to mention the crashing doesn't happen anymore. Link to comment Share on other sites More sharing options...
Kzisor Posted March 17, 2015 Share Posted March 17, 2015 @greatguys, here is why it doesn't work. self.task = self.inst:DoPeriodicTask(self.digesttime, function() self:TryDigest() end) self.inst:ListenForEvent("gotnewitem", function() if not self.task then self.task = self.inst:DoPeriodicTask(self.digesttime, function() self:TryDigest() end) end end) You can cancel a task with task:Cancel(). You will need to cancel the digester.task and create a new one with your new timer. Link to comment Share on other sites More sharing options...
greatguys Posted March 17, 2015 Author Share Posted March 17, 2015 @greatguys, here is why it doesn't work. self.task = self.inst:DoPeriodicTask(self.digesttime, function() self:TryDigest() end) self.inst:ListenForEvent("gotnewitem", function() if not self.task then self.task = self.inst:DoPeriodicTask(self.digesttime, function() self:TryDigest() end) end end) You can cancel a task with task:Cancel(). You will need to cancel the digester.task and create a new one with your new timer. Just did this and-Works flawlessly.Thank you! Link to comment Share on other sites More sharing options...
greatguys Posted March 18, 2015 Author Share Posted March 18, 2015 I tried to elaborate on the mod a little more by adding a max inventory option to it, however, it isn't going to well. After the lure plant eats something, it crashes giving this error: My modmain.lua is now this:local function Digestionist(prefab) if not GLOBAL.TheWorld.ismastersim then return inst end -- Hunger timer prefab.newdigest = GetModConfigData("timer") prefab.components.digester.digesttime = prefab.newdigest prefab.components.digester.task:Cancel() prefab.components.digester.task = prefab.components.digester.inst:DoPeriodicTask(prefab.components.digester.digesttime, function() prefab.components.digester:TryDigest() end) -- Inventory mod prefab:AddComponent("inventory") prefab.components.inventory.maxslots = GetModConfigData("items") print("Digest time is",prefab.components.digester.digesttime) print("Inventory slots are",prefab.components.inventory.maxslots)endAddPrefabPostInit("lureplant", Digestionist) Link to comment Share on other sites More sharing options...
greatguys Posted March 19, 2015 Author Share Posted March 19, 2015 Nevermind, I've got it Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now