Homebrew How can I put a "TIMER" so that later it executes an action

LoboNer

New Member
OP
Newbie
Joined
Jul 24, 2022
Messages
3
Trophies
0
Age
23
Location
Peru lmao
XP
40
Country
Peru
What I mean by "TIMER" is that after the time limit I gave to the timer it executes an action programmed in the code.

Something like I want to make a basic timer that counts as 6 seconds and after those 6 seconds pass it executes a code that I programmed like adding an image on screen etc.

Do you guys know how to do this? I am new to DS programming.

(I use libnds and the NightFox Lib)
 

mrparrot2

Well-Known Member
Member
Joined
Nov 29, 2021
Messages
110
Trophies
0
Age
29
Location
SP, Brazil
XP
582
Country
Brazil
Take a look at libnds/include/timers.h

The function `timerStart` last argument named `callback` receives a pointer to a function. This means you can do things like
```
void Add_Image_On_SeenBuff(void) {
// Do your things.
}
```
And then,

```
timerStart(arg1, arg2, arg3, Add_Image_On_SeenBuff)
```
I assume this works by issuing an interruption, so be careful about how long your code will take to run and possible race condititons by having a function interrupted in the middle of its execution.
 

plasturion

temporary hermit
Member
Joined
Aug 17, 2012
Messages
1,237
Trophies
2
Location
Tree
XP
3,535
Country
Poland
never used timer class, but it's very useful, other way you can define timer variable and place in the mainloop synchronized to vblank (60times per sec) something like...
int timer = 360;
If (timer && timer-- == 1){
// call function or do sort of things
}
or something similar in dozens different ways.
 

mrparrot2

Well-Known Member
Member
Joined
Nov 29, 2021
Messages
110
Trophies
0
Age
29
Location
SP, Brazil
XP
582
Country
Brazil
never used timer class, but it's very useful, other way you can define timer variable and place in the mainloop synchronized to vblank (60times per sec) something like...
int timer = 360;
If (timer && timer-- == 1){
// call function or do sort of things
}
or something similar in dozens different ways.
If you do not need your timer to be precise, then using a counter attached to vblank interrupt is a very good alternative. You can then use the hardware timer on tasks that actually require more precision.
 

Coto

-
Member
Joined
Jun 4, 2010
Messages
2,979
Trophies
2
XP
2,565
Country
Chile
Timer stuff you definitely want to use hardware for that since it's precise and wastes minimal CPU resources, here's an example implementing count in milliseconds and microseconds (DS is too slow for us,microseconds anyway):

https://bitbucket.org/Coto88/toolch...4403/src/common/hardware/timerTGDS.h#lines-54

https://bitbucket.org/Coto88/toolch...3/src/common/libhardware/timerTGDS.c#lines-27


Games use count in milliseconds (from timer or vblank counts) to make the game engine live at a certain pace.
I use it to synchronize the videoplayback to framerate in ToolchainGenericDS-multimediaplayer
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • BakerMan @ BakerMan:
    fucking hell i'm becoming a mini leo with the way i yap aren't i?
    +1
  • impeeza @ impeeza:
    I was unable to create the VM for the debloat windows, but found the video where I learned it:

    https://www.youtube.com/watch?v=mZm6mY3I7J4
    +2
  • BigOnYa @ BigOnYa:
    No you def no leo, and I like your insight. You are a smart Baked cookie.
  • K3Nv2 @ K3Nv2:
    Chicken drumsticks and sweet potato for dinner tonight turned out good
    +1
  • BakerMan @ BakerMan:
    "i promise not to get all political and/or philosophical"
    3 drinks later:
    "so yeah think for yourself and i think the government sucks"
    +1
  • K3Nv2 @ K3Nv2:
    Is @BigOnYa drunk again
  • BakerMan @ BakerMan:
    no, i was poking fun at myself
  • BigOnYa @ BigOnYa:
    Again? I have a IV feeding me so I never come down.
    +2
  • BakerMan @ BakerMan:
    because self deprecating humor is important, as long as it doesn't turn into self hate. because you can't really make fun of anyone if you can't even make fun of yourself
    +2
  • Psionic Roshambo @ Psionic Roshambo:
    Booze enemas are real lol
  • The Real Jdbye @ The Real Jdbye:
    that explains a lot
    +1
  • K3Nv2 @ K3Nv2:
    @BigOnYa, invented the first ever pill that gets you instantly hammered, now filling the streets of Miami
  • BigOnYa @ BigOnYa:
    That was what called a qaaulude, instant drunk, luckily they not around anymore.
    +1
  • K3Nv2 @ K3Nv2:
    Tylenol midday
  • Psionic Roshambo @ Psionic Roshambo:
    Ambian the stuff of dreams lol
  • K3Nv2 @ K3Nv2:
    Nyquill with grape juice
  • realtimesave @ realtimesave:
    wow that didn't work lol
  • realtimesave @ realtimesave:
    tried to paste a pic
  • K3Nv2 @ K3Nv2:
    Stop getting your creamy paste all over
    +1
  • impeeza @ impeeza:
    DO NOT WORK FOR ME :(
  • BigOnYa @ BigOnYa:
    I think he has a wedgie, and is afraid to fix it in public.
    +1
    Psionic Roshambo @ Psionic Roshambo: Thong +1