Weexer Posted February 17, 2019 Share Posted February 17, 2019 (edited) I'm really struggling to make this code work. When i'm killing dragonfly im getting server announce that "Dragonfly just spawned", thats working fine and i added only this announce line to make sure that code works on this part but the next part unfortunately not working (from adding component("timer")). How to make it work? (I know that full day in DST is 480 units from tuning.lua, and what i want to show is another message that "Dragonfly just spawned" after 10/480 day but it doesn't show up. Help please! local announce3_prefabs = { 'dragonfly', } for k, v in pairs(announce3_prefabs) do AddPrefabPostInit(v, function (inst) local function OnTimerDone(inst, data) if data.name == "regen_dragonfly" then TheNet:Announce("" ..inst.name.. "" ..announcestr.spawned.. "" ..announcestr.ending) end end local function announcement(inst, data) TheNet:Announce("" ..inst.name.. "" ..announcestr.spawned.. "" ..announcestr.ending) inst:AddComponent("timer") inst.components.timer:StartTimer("regen_dragonfly", 10) inst:ListenForEvent("timerdone", OnTimerDone) end local function extinction(inst) inst:ListenForEvent("attacked", announcement) end inst:ListenForEvent("death", extinction) end) end Edited February 17, 2019 by Weexer Link to comment Share on other sites More sharing options...
Ultroman Posted February 17, 2019 Share Posted February 17, 2019 (edited) inst:ListenForEvent("timerdone", OnTimerDone) You're not passing the 'inst' or 'data' objects along to the OnTimerDone function. You need to do: inst:ListenForEvent("timerdone", OnTimerDone, inst, data) Edited February 17, 2019 by Ultroman Link to comment Share on other sites More sharing options...
Weexer Posted February 17, 2019 Author Share Posted February 17, 2019 (edited) Unfortunately that didn't work @Ultroman Or maybe it works but something other is wrong? local announce3_prefabs = { 'dragonfly', } for k, v in pairs(announce3_prefabs) do AddPrefabPostInit(v, function (inst) local function OnTimerDone(inst, data) if data.name == "regen_dragonfly" then TheNet:Announce("" ..inst.name.. "" ..announcestr.spawned.. "" ..announcestr.ending) end end local function announcement(inst, data) TheNet:Announce("" ..inst.name.. "" ..announcestr.spawned.. "" ..announcestr.ending) inst:AddComponent("timer") inst.components.timer:StartTimer("regen_dragonfly", 10) inst:ListenForEvent("timerdone", OnTimerDone, inst, data) end local function extinction(inst) inst:ListenForEvent("attacked", announcement) end inst:ListenForEvent("death", extinction) end) end Edited February 17, 2019 by Weexer Link to comment Share on other sites More sharing options...
Ultroman Posted February 18, 2019 Share Posted February 18, 2019 Yeah, I was wrong. You don't need that. Remove it again. What have you done in terms of debugging? Did you debug the whole timer-thing? If you're unsure about debugging using print-statements, take a look at this post. Link to comment Share on other sites More sharing options...
Weexer Posted February 18, 2019 Author Share Posted February 18, 2019 @Ultroman I checked server.log on specific cluster where i tested mod and i found these lines in it: [00:00:41]: [(KU_GGbJlz1O) Weexer] ReceiveRemoteExecute(c_supergodmode()) @(-3.97, 620.90) [00:00:41]: God mode: true [00:00:46]: [(KU_GGbJlz1O) Weexer] ReceiveRemoteExecute(DebugSpawn("dragonfly",1)) @(-21.39, 621.16) [00:00:52]: [(KU_GGbJlz1O) Weexer] ReceiveRemoteExecute(ThePlayer.components.combat.damagemultiplier=3000) @(-21.61, 619.10) [00:00:52]: [string "../mods/Boss Status/modmain.lua"]:209: attempt to index global 'timer' (a nil value) LUA ERROR stack traceback: ../mods/Boss Status/modmain.lua:209 in (local) fn (Lua) <206-212> 209 line is => timer:StartTimer("announcer", 10) My updated code: for k, v in pairs(announce3_prefabs) do AddPrefabPostInit(v, function (inst) local function OnTimerDone(inst, data) if data.name == "announcer" then TheNet:Announce("" ..inst.name.. "" ..announcestr.spawned.. "" ..announcestr.ending) end end local function announcement(inst, data) if inst:HasTag("epic") then TheNet:Announce("" ..inst.name.. "" ..announcestr.spawned.. "" ..announcestr.ending) timer:StartTimer("announcer", 10) inst:ListenForEvent("timerdone", OnTimerDone) end end local function extinction(inst) inst:ListenForEvent("attacked", announcement) end inst:ListenForEvent("death", extinction) end) end Link to comment Share on other sites More sharing options...
Ultroman Posted February 18, 2019 Share Posted February 18, 2019 (edited) YAY, DEBUGGING So, it works now? If so, I'd probably label the timer something more unique than "announcer". Edited February 18, 2019 by Ultroman Link to comment Share on other sites More sharing options...
Weexer Posted February 18, 2019 Author Share Posted February 18, 2019 (edited) @Ultroman It's not working still I'm not sure why im keep getting error: attempt to index global 'timer' (a nil value) I'm trying to search mistake looking on timer.lua right now Edited February 18, 2019 by Weexer Link to comment Share on other sites More sharing options...
Ultroman Posted February 18, 2019 Share Posted February 18, 2019 You don't have a timer-variable, and timer isn't a global variable either, so there's no variable named timer, and you're trying to use a variable called timer. I think the problem is, that you're trying to add a Timer-component, but Dragonfly already has a Timer-component. Just use that component, instead of trying to make your own. Try this. If it doesn't work (or actually before you even test it) put in some print-statements everywhere, so you can see exactly what is being called and what isn't being called. local announce3_prefabs = { 'dragonfly', } for k, v in pairs(announce3_prefabs) do AddPrefabPostInit(v, function (inst) local function OnTimerDone(inst, data) if data.name == "regen_dragonfly" then TheNet:Announce("" ..inst.name.. "" ..announcestr.spawned.. "" ..announcestr.ending) end end local function announcement(inst, data) TheNet:Announce("" ..inst.name.. "" ..announcestr.spawned.. "" ..announcestr.ending) inst.components.timer:StopTimer("regen_dragonfly") inst.components.timer:StartTimer("regen_dragonfly", 10) inst:ListenForEvent("timerdone", OnTimerDone) end local function extinction(inst) inst:ListenForEvent("attacked", announcement) end inst:ListenForEvent("death", extinction) end) end Link to comment Share on other sites More sharing options...
Weexer Posted February 18, 2019 Author Share Posted February 18, 2019 @Ultroman sorry for making You trouble like noone else on forum haha I tried to "rebuild" code because unfortunately that wasn't solution. I made this: for k, v in pairs(announce3_prefabs) do AddPrefabPostInit(v, function (inst) local function OnTimerDone(inst, data) if data.name == "dragon_announce" then TheNet:Announce("" ..inst.name.. "" ..announcestr.spawned.. "" ..announcestr.ending) end end local function announcement(inst, data) if inst:HasTag("epic") then TheNet:Announce("" ..inst.name.. "" ..announcestr.spawned.. "" ..announcestr.ending) inst.components.timer:StopTimer("dragon_announce") inst.components.timer:StartTimer("dragon_announce", 10) end end inst:ListenForEvent("timerdone", OnTimerDone) local function extinction(inst) inst:ListenForEvent("attacked", announcement) end inst:ListenForEvent("death", extinction) end) end After printing method it looks like local functions with name "extinction", "announcement" are called but i'm not sure how to check if it goes to "OnTimerDone" function (it only show message then i don't know if it create that timer named "dragon_announce" - well i took more unique name for that Also i don't know how to print those timer value. Any ideas? Link to comment Share on other sites More sharing options...
Ultroman Posted February 18, 2019 Share Posted February 18, 2019 The OnTimerFunction is your own, so you can just put print-statements in it. There's a lot of weird going on in your code. I put in some comments to tell you what the code you've written does. Read from the bottom and upwards. for k, v in pairs(announce3_prefabs) do AddPrefabPostInit(v, function (inst) local function OnTimerDone(inst, data) if data.name then print("OnTimerDone => name: "..data.name) else print("OnTimerDone => No name") end if data.name == "dragon_announce" then print("OnTimerDone => dragon_announce was succesfully identified.") TheNet:Announce("" ..inst.name.. "" ..announcestr.spawned.. "" ..announcestr.ending) end end local function announcement(inst, data) -- If the Dragonfly has the tag "epic" (doesn't it always?), make an announcement that it has -- been spawned. This is realy weird, since you call this in the event that a Dragonfly gets attacked. -- And as I mention later, the Dragonfly you're listening to, is dead -- and therefore despawned immediately after "extinction" is done. if inst:HasTag("epic") then print("Attack initiated on "..inst.name) TheNet:Announce("" ..inst.name.. "" ..announcestr.spawned.. "" ..announcestr.ending) -- Stop any currently running timer inst.components.timer:StopTimer("dragon_announce") -- Start new timer inst.components.timer:StartTimer("dragon_announce", 10) end end -- Upon Dragonfly death, start listening for an attack on it...seems weird...it'll be despawned in the next frame. -- The next Dragonfly is a new instance of the Dragonfly. It won't inherit your timers. local function extinction(inst) -- When a Dragonfly is attacked, call the function "announcement". inst:ListenForEvent("attacked", announcement) end -- Execute the function "OnTimerDone" when the timer on the Dragonfly pushes a "timerdone" event. inst:ListenForEvent("timerdone", OnTimerDone) -- Execute the function "extinction" in the event of a Dragonfly dying. inst:ListenForEvent("death", extinction) end) end 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