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
588
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,247
Trophies
2
Location
Tree
XP
3,564
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
588
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
  • Sicklyboy @ Sicklyboy:
    I used to drink alcohol fairly often. Never to the point of it being a problem, but like 2-3 beers with dinner each night, or a few cocktails or glasses of Scotch or something. Started smoking/vaping weed a lot a few years back which killed 90% of my interest in booze. Now I stopped smoking/vaping weed as much and just deal with life the boring way most of the time
    +1
  • Xdqwerty @ Xdqwerty:
    I only drank alcohol once and it was by accident
  • Xdqwerty @ Xdqwerty:
    I didnt know it was beer, it was on a juice bottle
  • SylverReZ @ SylverReZ:
    Yeah, I'm addicted to smoking, sadly. It's very addictive but I wish I didn't start.
  • K3Nv2 @ K3Nv2:
    May just order a 5700g for a nas/emulation set up tbh
  • Xdqwerty @ Xdqwerty:
    @SylverReZ, atleast you were asleep on 4/20
    +1
  • Xdqwerty @ Xdqwerty:
    @SylverReZ, you played that Mario flash game called Mario 63?
  • SylverReZ @ SylverReZ:
    @Xdqwerty, No, but I've seen it on Vinesauce's stream.
  • Xdqwerty @ Xdqwerty:
    @SylverReZ, that game is one of the reasons i met newgrounds bc the full versión of it is in that site
  • Xdqwerty @ Xdqwerty:
    Also somebody is remaking it
  • Xdqwerty @ Xdqwerty:
    @SylverReZ, the other game where I found newgrounds is new york shark
    +1
  • SylverReZ @ SylverReZ:
    Spoke to Tom Fulp the other day, if he can find his old Newgrounds site content like the mini Flash animations from the 2000's that played on the portal.
  • SylverReZ @ SylverReZ:
    So far no response, but he did say that he'll find them. Wayback Machine doesn't have em.
  • Xdqwerty @ Xdqwerty:
    @SylverReZ, atleast the 1999 versión of pico's school is avaliable (the difference between it, the 2006 versión and the 2016 versión is that the speed of the game depends of the speed of your computer and that it had the og soundtrack)
  • SylverReZ @ SylverReZ:
    @Xdqwerty, Another being Pico VS Bear, the original 1999 version before Jim Henson filed a DMCA takedown.
    +1
  • Xdqwerty @ Xdqwerty:
    The 2006 versión was made when the flash portal was made
  • SylverReZ @ SylverReZ:
    Many people thought it was lost, but was discovered that he hid it on the same page.
  • Xdqwerty @ Xdqwerty:
    @SylverReZ, although the "secrets" system where the game was has been removed. Also pico vs uberkids had a netplay versión that was shutdown, although the swf file has been found
  • SylverReZ @ SylverReZ:
    @Xdqwerty, Nope. There are two download buttons on the same page, where you can download the original under a file called "bear.exe". "bear2.exe", however, is the updated game in a Flash projector. P.s. this was on the archived Pico page from 2000.
  • SylverReZ @ SylverReZ:
    @Xdqwerty, That's been there for a long time, too. People who search for lost media don't look hard enough lmao.
    +1
  • Xdqwerty @ Xdqwerty:
    @SylverReZ, also the pico 2 demos used to be only for the newgrounds patrons but they are on internet archive too (https://archive.org/download/picos_school_2)
    +1
  • Xdqwerty @ Xdqwerty:
    Iirc the demos were removed from newgrounds in 2022
    Xdqwerty @ Xdqwerty: Iirc the demos were removed from newgrounds in 2022