ID:160552
 
I've looked around the web, and even here on Byond. Of what I did find wasn't much help. I'm a beginner, so what is a simple way of making a Timer for mini games? I tried using sleep, and the timer would never reset when the mini game was played again.
Well, however u get in mini-game, in the join code, make it chanqge time back.
Okay, i'm sure some OG of BYOND will come and correct me because there is probably some pre-made proc/var for it, though you can try this, I made a lil small demo for it.

Really this depends on how you do it, there is this way...
mob
var/Timer=0
Stat()
statpanel("[name]")
stat("Timer: ","[Timer]")
verb
StartTimer()
var/T=input("How long do you want the timer to last for?(In Seconds)","Timer") as num
Timer(T,src)
proc/Timer(Time,var/mob/M)
M.Timer=Time
if(Time<1) return
while(Time)
Time--
M.Timer=Time
sleep(10)
M<<"Time is out! DIE NOA!"

You can edit that however you want, really you just use the proc to make an input in seconds and it displays that in the stats, though you can change it to wherever you want to display it, or add minutes and such the same way.
8BitGeek wrote:
I've looked around the web, and even here on Byond. Of what I did find wasn't much help. I'm a beginner, so what is a simple way of making a Timer for mini games? I tried using sleep, and the timer would never reset when the mini game was played again.

The code bellow is suppose to be used as an example. Not as runnable code.
var/TimeCounter=0

proc/StartTimer()
set background = 1

TimeCounter = 0

spawn while(TimeCounter>=0)
sleep(10)
TimeCounter++

proc/EndTimer()
TimeCounter = -1


The above code would be used by running the StartTimer procedure when the mini-game begins. Then run EndTimer procedure when the mini-game ends.
In response to Bakasensei
Bakasensei wrote:
Okay, i'm sure some OG of BYOND will come and correct me because there is probably some pre-made proc/var for it, though you can try this, I made a lil small demo for it.

Really this depends on how you do it, there is this way...
mob
> var/Timer=0
> Stat()
> statpanel("[name]")
> stat("Timer: ","[Timer]")
> verb
> StartTimer()
> var/T=input("How long do you want the timer to last for?(In Seconds)","Timer") as num
> Timer(T,src)
> proc/Timer(Time,var/mob/M)
> M.Timer=Time
> if(Time<1) return
> while(Time)
> Time--
> M.Timer=Time
> sleep(10)
> M<<"Time is out! DIE NOA!"

You can edit that however you want, really you just use the proc to make an input in seconds and it displays that in the stats, though you can change it to wherever you want to display it, or add minutes and such the same way.

I kinda understand it, but could you maybe explain the proc to me, so i know for sure what I'm thinking is correct. Also I noticed after about every 4 numbers in the countdown in that code, the next number would last 2 sec.
In response to 8BitGeek
Its because BYOND updates the stat() menu every .8 seconds.

Also its very simple, you should get what it means.
In response to Bakasensei
Bakasensei wrote:
Its because BYOND updates the stat() menu every .8 seconds.

Also its very simple, you should get what it means.

Your right, I'm sorry, I need to stop trying to shove more stuff in my brain when I'm stressed out
In response to 8BitGeek
This may, or may not work, but of course, it's just an example:

mob/proc
TimerProcedure()
if(!src.counter)
src << "You start the timer!"
while(src.counter>=0)
sleep(10)
src.counter+=1
else
src << "You end the timer!"
src.counter=0
mob/var/counter=0
mob/verb/Toggle_Timer()
src.TimerProcedure()
mob/verb/Show_Timer()
if(src.counter>=1)
src << "Timer: [src.counter]"
else
src << "You have not started the timer!"


~Duper
If you're interested, I wrote a timer library last month. I think I have yet to use it in a project, but there is a demo included.