Jump to content

Save and restore tasks?

Recommended Posts

What is the proper way to save and restore tasks in a component?

Eg. in my component I want to call a function after one day:

self.task = self.inst:DoTaskInTime(TUNING.TOTAL_DAY_TIME,function(inst) ... end)

When I now quit and load the game, this task has stopped, right?
So how to resume the task with the time left?

I could get the timeleft of the task when saving and start the task with that time again when loading, but this is a dirty workaround and won't work well I think...

Link to comment
Share on other sites

11 minutes ago, CarlZalph said:

Couple of ways from here:

As for being proper it's more efficient to have just one timer going and snapshot a timestamp than it is to poll multiple times.

thanks. Yes this was also the way I tried it already, but I hoped there would be a better way :D
To get the "timeleft" we can also use "GetTaskRemaining(self.task)".

But the reason why I was searching for another way was, that when the task is finished and the function called, the timeleft is not set to nil automatically. So I have to set it nil in this function. My code is a bit encapsulated, that's why I feared it could cause problems.
But I will do it that way now and try to make sure that everything works.

Edited by Serpens
Link to comment
Share on other sites

I was looking into that thread yall linked on here also and when trying to implement into my mod to keep track of a timed speed boost after eating an item because the boost is completely removed upon entering a cave. But that fix is seeming to require a dedicated server and I dont know enough of LUA to really disect it and learn how to adjust it. Yall got any ideas?

Hot Coffee.rar

Edited by tdawg3000
mod upload
Link to comment
Share on other sites

I'm not sure if I should find it good that you are working on such a mod or find it bad.
I think such a mod requires advanced skills and is not good for a beginner.
At least finish it with help of advanced modders first, before publishing it.. (I just don't like poor coded mods in the workshop)

But of course everyone is a beginner first, so I will try to help you. But I fear we would need to rewrite your whole mod from scratch, that's why I did not wrote earlier about your mod...

It would be best to make a new thread specially for your mod.
Tomorrow I will download it and tell you what you can improve and also try to find a solution for problems.
I'm also no expert modder, but at least advanced, so I think I can find good solutions.

Of course CarlZalph (expert modder) and others are also welcome to help :)

(I don't want to sound rude, sry)

Edited by Serpens
Link to comment
Share on other sites

On 5/2/2017 at 6:48 PM, Serpens said:


No offence taken man, and its really not such an advance mod, just a item with a speed boost. >.< Lol

 I usually keep my code pretty neat and clean so its easy to expand on. But since then ive already found a fix for loading into caves while saving the time of the boost and reapplying when entered, the mushroom example in the thread linked above helped. 

With that being said I uploaded it to workshop for specific friends to download because its just easier for them to install mod that way. And i think taking on challenging task is what teaches us, to start with a begginer thing by following a tutorial step by step to reproduce the exact same result with nothing but a different name is lame and wouldnt teach my anything, I already have a background in coding just new to Lua

But if you want to take a look at it and have any tips on improving id love to hear it thanks for all the help!

Edited by tdawg3000
Link to comment
Share on other sites

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