Jump to content

Timer or coroutine


srslyyyy

Recommended Posts

  • Scripting Moderators

Hey. As title says, which will be better for my case? I'm planning to create a custom admin panel for myself. Will need it for temporary vips and bans. As far i remember admin panel was using coroutines for this stuff. Any advices?

Link to comment

Coroutines are used to pause execution of a routine (a section of the code) whilst waiting for a callback, for example. They aren't a replacement for timers, but rather an addition. If you want to pause and then resume coroutines after some time elapses, you'd be using setTimer as well.

If you want temporary vips and bans you'd be best using traditional data storage (XML files, JSON files, SQL, etc. -- preferably SQL) with timestamps to mark end-time and setTimer to trigger the function that removes the vip status or ban. That way you can restart timers when your resource restarts for any reason, since you know the current timestamp and end-timestamp, you can calculate how long setTimer you need.

Edited by MrTasty
  • Like 4
Link to comment
  • Scripting Moderators
10 hours ago, MrTasty said:

Coroutines are used to pause execution of a routine (a section of the code) whilst waiting for a callback, for example. They aren't a replacement for timers, but rather an addition. If you want to pause and then resume coroutines after some time elapses, you'd be using setTimer as well.

If you want temporary vips and bans you'd be best using traditional data storage (XML files, JSON files, SQL, etc. -- preferably SQL) with timestamps to mark end-time and setTimer to trigger the function that removes the vip status or ban. That way you can restart timers when your resource restarts for any reason, since you know the current timestamp and end-timestamp, you can calculate how long setTimer you need.

Thanks for answer. I'm familiar with JSON, so i will use it for sure. About timers - ok, that is something similar what i wanted to do. Timer on server-side, which will check for endtime. Wasn't sure, since i'm rarely using timers, the only exception is buffer for triggers.

Link to comment
  • Moderators
On 29/11/2019 at 22:43, majqq said:

Wasn't sure, since i'm rarely using timers

I am just wondering, Mrtasty explained what the coroutine does.

But do you also understand why they are used for something like bans? Temporarily stopping code isn't something you do without a good reason.

Link to comment
  • Scripting Moderators
24 minutes ago, IIYAMA said:

I am just wondering, Mrtasty explained what the coroutine does.

But do you also understand why they are used for something like bans? Temporarily stopping code isn't something you do without a good reason.

As you can see - didn't asked, i also never used them. But as first i thought this is "replacement" for timers.

About question - maybe because there's no need to check for ban timeleft if there's no bans at all? If i am wrong, please correct me :D

Edited by majqq
Link to comment
  • Moderators
14 hours ago, majqq said:

As you can see - didn't asked, i also never used them. But as first i thought this is "replacement" for timers.

It is mainly used to break a big task in separated sub-tasks. Your computer can't finish the big task in one run without blocking everything else (other resources and applications like your browser).

 

For example:

You have to do 10 exams and for that you have write a script that would determine which exams you have to learn for.

For learning each exam you need 4 hours.

You are a human, so you need every day atleast 13 hours resting/sleep, breakfast, dinners etc.

-----

No worries, you do not need to program this. But there is one thing that matters, which is that you can only finish 2.75 exams per day.

 

In Lua there is also limit, just run this to find out:

while true do
  
end

------

Coroutines are used to pause the code when the duration takes to long. The timer is used to resume the code at a new moment. Now an impossible task can become smaller possible tasks.

 

 

 

 

 

 

 

 

Edited by IIYAMA
  • Like 1
Link to comment

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...