Timers: How do they work?
#1

I know this is not entirely related to Pawn scripting, but I just can't stop thinking: how do timers work?
I've been asking myself this because I'm developing a pong clone for my programming class, and need to run functions after a determined amount of time, such as speed increasing and menu related stuff. I created a delay function using ticks to better control the speed of the ball, but it just wouldn't work for speed increasing, since I want to increase speed every ten seconds.

What I mean is: How would a SetTimer function look like in assembly code, for example? Would it be like a main loop running constantly and checking if an amount of time has passed? If I'm running a program, which has an order of execution, calling a function by a timer would be like interrupting this order of execution to do another function, and then returning to the original point?

I know these will be newbie questions for some, but I am very curious about this.
Reply
#2

The link below countain everything that is needed to know what is a settimer.

https://sampwiki.blast.hk/wiki/SetTimer
Reply
#3

Quote:
Originally Posted by leonardo1434
Посмотреть сообщение
The link below countain everything that is needed to know what is a settimer.

https://sampwiki.blast.hk/wiki/SetTimer
Thats not what he asks,

He asks how do they work, like how does the language pawn executes them,
not how to set them
Reply
#4

Quote:
Originally Posted by leonardo1434
Посмотреть сообщение
The link below countain everything that is needed to know what is a settimer.

https://sampwiki.blast.hk/wiki/SetTimer
Not what I meant at all.
I know how to use the function and how does it work, but I would like further knowledge about the logic behind it.
I mean, how would an instruction order work by defined amounts of time?
Reply
#5

Timers are just...timers.
You set it, you let it work, then boom, you get results...
for example, I want a timer and loops through the whole online players in my server, and then check for a specific aspect in them (like if they are cops, terrorists, admin etc..)
or, I can just set a timer to send a timed message, reminders, MOTD's etc...

how timers work?
It's seriously and insanly easy!
For instance, I want a timer that goes through the entire online players, and checks if they are VIP's...
So, here's what I do
pawn Код:
public OnGameModeInit()
{
    SetTimer("VIPChekcer", 1000, true); // "1000" represents the time, "true" means the timer will repeat itself after 100 millisecs (1 second)
    return 1;
}
So this basicly sets a timer in my script...now to edit "VIPChecker" content to find VIP's... (or do anything I like)
pawn Код:
forward VIPChecker();
Just place that on top of your script, it basicly "forwards" a public function...now to make this public function, just do this, anywhere. (as long as it is AFTER the line where we forward'd the public function)
pawn Код:
public VIPChecker()
{
    for(new i = 0; i < MAX_PLAYERS; i++) // loops through the whole online players.
    {
        if(PlayerInfo[i][pVIP] == 1) // checks if the players (represented by "i") are VIP's or not.
        {
            // if they are I'll send them a message.
        }
    }
}
Reply
#6

Still not what he is asking,

He is looking for the machine logica, like the way it works inside a computer
Reply
#7

Well, i don't know binary language, so it's impossible to give that but, as far as i know, it works like that:

When a timer is set, the machine creates a countdown, when this countdown ends up, it does the result. Just like a bomb..

Like, I want to eat a chocolate in 10 seconds, i will think: I will eat it in 10 seconds. Than i count 10 seconds, 9, 8, 7, 6, 5, 4, 3, 2, 1 and than i eat it..

They also set a variable that says what timer is it.. Like, you create a timer for speed, and it will create a countdown saying speed, so it knows when it's done, it has to execure speed..
Reply
#8

Quote:
Originally Posted by milanosie
Посмотреть сообщение
Thats not what he asks,

He asks how do they work, like how does the language pawn executes them,
not how to set them
Quote:
Originally Posted by milanosie
Посмотреть сообщение
Still not what he is asking,

He is looking for the machine logica, like the way it works inside a computer
Dude seriously stop commenting if you're here to troll and tell people what to do. Lets see what you got before anything.

Back on topic: Timers are set to work as regular timers in real life. There is really nothing that complex to it.
Reply
#9

Quote:
Originally Posted by Edward156
Посмотреть сообщение
Dude seriously stop commenting if you're here to troll and tell people what to do. Lets see what you got before anything.
He said exactly what I meant in my first post, he's not telling anyone what to do.
I created this post as a scripting discussion, so any answers relating to the subject are valid.
Also, if someone had the answer, this was to serve as a good resource for those who are studying computer science.
I am going to research about the subject, and post here if I find something.

btw thanks for everyone who took the time to try to answer me
Reply
#10

I didn't mean to imply that at all, really.
I don't look at it as a "c programming language" question or whatever, but as a generic programming question.
If my topic is not in the purpose in this forum, then I apologise. Still, I would like to find the answer and post it here, merely as a curiosity resource.

Edit: Just found out about this topic, very useful for me and those looking into the matter in question. Check this also.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)