Jump to content

Recommended Posts

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.

  • Health 1
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.

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.

 

  • Like 1
  • Health 1
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)?

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.

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 by penguin0616
  • Like 1
  • Thanks 1
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!

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.

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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...