Argonwolf Posted January 4, 2021 Share Posted January 4, 2021 Every example I've seen of that function has been attached to a prefab instance. Is there a way to do it statically/globally in modmain.lua? Link to comment https://forums.kleientertainment.com/forums/topic/125728-how-can-i-doperiodictask-from-modmainlua/ Share on other sites More sharing options...
Wonderlarr Posted January 5, 2021 Share Posted January 5, 2021 DoPeriodicTask is specifically intended to be used on top of something, you can't just run it alone as far as I know, however you COULD just run it using the player character, with something like GLOBAL.ThePlayer:DoPeriodicTask(20, FunctionToBeatAllFunctions) I don't see why that wouldn't work, but you may be trying to do something really weird. If you don't like this, or it doesn't work, and you're trying to time events or something, you may want to look into a non networked entity. It's used for things like Meteor Spawners, and they'd be great for something like a timer entity if you really needed it. 1 Link to comment https://forums.kleientertainment.com/forums/topic/125728-how-can-i-doperiodictask-from-modmainlua/#findComment-1413511 Share on other sites More sharing options...
Argonwolf Posted January 5, 2021 Author Share Posted January 5, 2021 4 hours ago, TheSkylarr said: DoPeriodicTask is specifically intended to be used on top of something, you can't just run it alone as far as I know, however you COULD just run it using the player character, with something like GLOBAL.ThePlayer:DoPeriodicTask(20, FunctionToBeatAllFunctions) I don't see why that wouldn't work, but you may be trying to do something really weird. If you don't like this, or it doesn't work, and you're trying to time events or something, you may want to look into a non networked entity. It's used for things like Meteor Spawners, and they'd be great for something like a timer entity if you really needed it. What I'm trying to do is have a repeating event (once per second or so) that iterates over all chest entities in the world, reading their contents as well as checking proximity to players. If I attach the periodic task to the chests (which seems like the way to go atm), will I still be able to keep the mod purely server-side? That's my biggest overarching goal with this mod, is to have it only server side so the players' client doesn't have to do anything or download any assets. Link to comment https://forums.kleientertainment.com/forums/topic/125728-how-can-i-doperiodictask-from-modmainlua/#findComment-1413601 Share on other sites More sharing options...
penguin0616 Posted January 5, 2021 Share Posted January 5, 2021 1 hour ago, Argonwolf said: will I still be able to keep the mod purely server-side? That's my biggest overarching goal with this mod, is to have it only server side so the players' client doesn't have to do anything or download any assets. Your code won't run on clients unless you specify that it should in the modinfo. 1 hour ago, Argonwolf said: What I'm trying to do is have a repeating event (once per second or so) that iterates over all chest entities in the world, reading their contents as well as checking proximity to players. You can use AddSimPostInit to wait until the world loads, then attach your DoPeriodicTask to the world. Alternately, as you said, you can attach it to chests. Â 1 1 Link to comment https://forums.kleientertainment.com/forums/topic/125728-how-can-i-doperiodictask-from-modmainlua/#findComment-1413621 Share on other sites More sharing options...
Argonwolf Posted January 5, 2021 Author Share Posted January 5, 2021 44 minutes ago, penguin0616 said: Your code won't run on clients unless you specify that it should in the modinfo. You can use AddSimPostInit to wait until the world loads, then attach your DoPeriodicTask to the world. Alternately, as you said, you can attach it to chests. Â So to attach the task to the world, would I just do GLOBAL.DoPeriodicTask(args)? Or is it World.DoPeriodicTask(args)? Link to comment https://forums.kleientertainment.com/forums/topic/125728-how-can-i-doperiodictask-from-modmainlua/#findComment-1413641 Share on other sites More sharing options...
penguin0616 Posted January 5, 2021 Share Posted January 5, 2021 Here's a rough example. @Argonwolf AddSimPostInit(function() TheWorld:DoPeriodicTask(SOME_TIME, function() blahblahblah end) end) 1 1 Link to comment https://forums.kleientertainment.com/forums/topic/125728-how-can-i-doperiodictask-from-modmainlua/#findComment-1413642 Share on other sites More sharing options...
Argonwolf Posted January 5, 2021 Author Share Posted January 5, 2021 Cool, thanks! One more quick question: Is there any limit to what you can execute in the console? If I want to test out these functions individually in the console so I don't have to resave the mod and reload the server every time I mess something up, is that possible? Would I be able to initiate said task from console? I think that'd be pretty handy and I know the console can run a lot of just straight up code rather than being limited to its commands (advantage of an interpreted language I reckon), but IDK if I could cause serious problems doing that, if it's even possible. Link to comment https://forums.kleientertainment.com/forums/topic/125728-how-can-i-doperiodictask-from-modmainlua/#findComment-1413643 Share on other sites More sharing options...
penguin0616 Posted January 5, 2021 Share Posted January 5, 2021 (edited) 4 minutes ago, Argonwolf said: Is there any limit to what you can execute in the console? You can only fit about 512 characters in the console. A lot of mod functions (such as AddSimPostInit) don't work in the console. If it's not a mod function, then you can probably do it in there. 4 minutes ago, Argonwolf said: Would I be able to initiate said task from console? Yep. 4 minutes ago, Argonwolf said: so I don't have to resave the mod and reload the server every time I mess something up, I personally just prefer making the mod change, saving the file, and using c_reset() to reload the world. Pretty efficient for me, unless you're working with assets. Edited January 5, 2021 by penguin0616 1 1 Link to comment https://forums.kleientertainment.com/forums/topic/125728-how-can-i-doperiodictask-from-modmainlua/#findComment-1413644 Share on other sites More sharing options...
Argonwolf Posted January 5, 2021 Author Share Posted January 5, 2021 1 minute ago, penguin0616 said: You can only fit about 512 characters in the console. A lot of mod functions (such as AddSimPostInit) don't work in the console. If it's not a mod function, then you can probably do it in there. Yep. I personally just prefer making the mod change, saving the file, and using c_reset() to reload the world. Pretty efficient for me, unless you're working with assets. Perfect, thank you! My computer's a toaster, so even though it can by some miracle run DST pretty well, it can take a couple minutes to reboot a server even without caves. It's nice to know I can debug and experiment in real time. I can't wait to try this stuff out; thank you! Link to comment https://forums.kleientertainment.com/forums/topic/125728-how-can-i-doperiodictask-from-modmainlua/#findComment-1413645 Share on other sites More sharing options...
Argonwolf Posted January 5, 2021 Author Share Posted January 5, 2021 2 hours ago, penguin0616 said: Here's a rough example. @Argonwolf AddSimPostInit(function() TheWorld:DoPeriodicTask(SOME_TIME, function() blahblahblah end) end) When I put this in my modmain file (I replaced SOME_TIME with 5 and blahblahblah with the Delete All command from the DST command list on the wiki), it crashes saying "attempt to index global 'TheWorld' (a nil value)". I'm not sure what I've done wrong. Link to comment https://forums.kleientertainment.com/forums/topic/125728-how-can-i-doperiodictask-from-modmainlua/#findComment-1413681 Share on other sites More sharing options...
penguin0616 Posted January 6, 2021 Share Posted January 6, 2021 Try GLOBAL.TheWorld 1 1 Link to comment https://forums.kleientertainment.com/forums/topic/125728-how-can-i-doperiodictask-from-modmainlua/#findComment-1413684 Share on other sites More sharing options...
Argonwolf Posted January 6, 2021 Author Share Posted January 6, 2021 8 minutes ago, penguin0616 said: Try GLOBAL.TheWorld That did the job, thank you. I think any additional questions I have (I have tons) would be better served in newer threads tailored to them, but thank you for all your help, because as you probably guessed, I am brand-new to modding DST. Day zero. Link to comment https://forums.kleientertainment.com/forums/topic/125728-how-can-i-doperiodictask-from-modmainlua/#findComment-1413687 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