proc
AutoUnmute()
for(var/mob/A in Muted)
Muted.Remove(A)
world << "All people muted are now unmuted!"
Problem description:
I was wondering which proc would be the best to use here to check every hour or so..
ID:139783
Aug 26 2010, 12:59 pm
|
|
Code:
proc Problem description: I was wondering which proc would be the best to use here to check every hour or so.. |
In response to Midgetbuster
|
|
Lol that was just an example, I was gonna make a verb for that proc... I just wanted to know which proc is the best to use for that kind of proc.. here's the real thing I want to put proc on.
world but doing this makes my server lag. |
Just store the time the mute is going to expire, and check in the say proc.
var Easiest thing in the world! |
In response to Ter13
|
|
Lol.. Thanks but I want to know which procs(Goto, Return or While) are good for those kind of proc.
|
In response to NarutoBleach
|
|
most people would advise you against using a goto loop anywhere in your code. It's generally regarded as a poor technique, though it does have uses in certain places. They just aren't common anymore.
For and while are almost identical, except for allows some more convenience arguments for tighter control, and compact code. For also will only run one time for every object in a list, and while will run as long as there ARE objects in a list, and not actually iterate through them. If you want an infinite loop, I'd suggest building it as such: proc Still, this approach has some serious problems, for one, you need to set world.loop_checks to 0, otherwise the world will error out and cause an infinite loop error. There are much, much more elegant approaches, and checking every mob in the world to see if it has a client is just poor design. It would be better to store a list of players, and maintain it on login/logout, and loop through that. It would be even better to build a system that updates rankings ONLY when they change, instead of doing it periodically. For scheduling infinite loops and timed behavior, I don't even recommend using more than a single logic loop. I usually build an event queue, and then only keep one pending event going at a time. The queue just sorts events by order of occurrence, and then waits until it's time to call the next event. When the queue is modified, however, it is possible to interrupt a spawn by tying the code to a datum, and deleting that datum. I just keep pushing and popping events off the queue, and sort them as they are added, so that I can schedule events without having all kinds of hanging spawns all over the place, and can cancel events if I need to. |
In response to Ter13
|
|
xD I have world loop check set to 0... and I see.. though I'm not a really code coder, just a beginner so doing that would be hard for me. :P
|
In response to NarutoBleach
|
|
goto, return, and while are used for completely different things. You might as well be asking whether you should be using a wrench or a vegetable.
return is used to immediately end a proc and return a value to the calling proc. So, for example, if you wanted a proc to add two numbers, return would be used to return the result. while is used to create a loop, in order to perform something multiple times. goto is used for getting people to yell at you for using goto, because it is terrible and bad and you should never, ever use it. |
In response to Garthor
|
|
It's an artifact from the linear programming days... Not so much a useful thing anymore.
|
In response to Ter13
|
|
Ter13 wrote:
It's an artifact from the linear programming days... Not so much a useful thing anymore. I'm not sure what goto has to do with linear programming. Goto can always be replaced with a loop or if statement. The situations where using the goto statement is the best option are rare. Avoiding goto is a good rule of thumb. In BYOND the goto statement is particularly useless because it's very limited - you can't jump from one proc to another. This makes it even more likely that you won't need to use it. In other languages the goto statement may be less restricted and can be used to make up for the lack of other language features (most notably try and catch) but this is not the case in DM. |
In response to Forum_account
|
|
Agreed; linear programming was probably the wrong terminology to use.
Back before object oriented programming, and event-based architectures, goto was used heavily in game development (look at bastardized programming languages like early basic), and is more of a vestigial syntax feature, if you will. |
Consider this scenario. You have just muted someone at 11:58am and you want their mute to be half an hour. in 2minutes time when the auto unmute kicks in they will be unmuted.
You should look into realtime mutes, action locks. or just using a basic spawn() or sleep() code and have the mute var tmp.