Jump to content

Recommended Posts

Hi,

I am quite new to modding DST, but understand most of the basic concepts. My only question at the moment is, how I can get any function called every update frame. I've found the update.lua script with an Update(dt) function, but don't know how I can hook that function (to replace it with my own, call the old update and then do my stuff).

If anyone could point me to a solution there would be great, this is what I tried last:

local update = _G.require("update")

AddGlobalClassPostConstruct("update", "Update", function(dt)
	update.Update(dt)
	print("test")
end)

Thanks in advance!

It depends on what you want to do. For stuff like new components or classes there are OnUpdate methods that are already ran automatically already. If you want to do something with a custom character or a custom mob there is an "updatelooper" component that could help you.

If you still need to strictly hook up to the main update function you can do it like this:

require("update")

local old_Update = GLOBAL.Update
GLOBAL.Update = function(...)
    print("Updating...")

    old_Update(...)
end

 

Yes, that's what I needed, but maybe one of your other solutions could work at least as well.
I want to make a client side mod to assist in making self-fertilizing giant crops, so one part is to display the different possible placements there are, but also it should monitor the plants for water and when they need care, so there should either be a timer or if that doesn't work just an alert when they need something. For the timer and checking on the crops you want to monitor I wanted to use the update function.

Could one of the other solutions be better there?

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...