❔ Timer
Is it possible to add a timer that always counts down no matter where i am in the program ?
29 Replies
I want a timer in my code to end the game after 2 mins has gone by
(if it is can you not say the code but point me in the direction so i can work it ou tmyself)
i use visual studio
yeah but which kind of project
well mind explaining the problem a bit more detailed? what technologies are you using? unity? wpf? maui? blazor?
in visual studio
its a game
and iw ant it to end after 2 mins
visual studio is an ide
so is it possible ?
yes
So.
Do you know a bit of you way around DotNET?
or are you just starting out and curious of what C# can do?
Since you're not responding, maybe are asleep or otherwise occupied I will Give you a few demonstrations of C# Programs on Date, Time & Year, To help you on your way dealing with time in C#
https://learn.microsoft.com/en-us/dotnet/api/system.datetime?view=net-7.0
This is a documentation page dealing with Time for C#/dotNET
DateTime Struct (System)
Represents an instant in time, typically expressed as a date and time of day.
Crudely,
We could get Date and time thusly:
i just wanna know if its possible as it would require going through something seperate to the main program while the main program running
I have to forewarn you I am close to ending my day here but I can give you a bump over the hill, is that good to you?
I'm not spoonfeeding you the answers but I can help you out with showing some work. Good?
First and foremost, Yes I think it is workable. But I think you are gonna have to deal with threading next to Daytimefunctionality as well.
Which is a bit rough for a starter.
Like, crudely,
This would be a countdown timer for 120 seconds. (2 minutes)
But that timer has to "Click" some other function, right?
Otherwise this program runs and shuts after having count down without no one any the wiser.
listen, I want to help out, but you are hardly giving me any responses to my questions which is kind of killing communication for me.
would that run no matter what line the pogram is on
It should run no matter what, unless your surrounding code dictates other standards.
what ya mean by dicated other standards ?
if some other code says: no this
private int _countDown = Completelysomethingelse
or a million other things.
It just means to say, if this is nearly the only thing in main()
then it should be fine.
If you can see something that is "conditioning" or "leveraging" the datetime struct otherwise, you get different results.
I'm sorry for the wordy-ness, but that's part of the territory.
Code = language--
Please read the contents of this link
https://learn.microsoft.com/en-us/dotnet/api/system.datetime?view=net-7.0
It explains a lot about using dates, time and years in C#
DateTime Struct (System)
Represents an instant in time, typically expressed as a date and time of day.
k
One simple instance:
this gets the local time.
(I'm letting you read quietly in a bit, but I think You are running to fast for your boots)
Get the gist of date-time first, then after, learn to condition it.
take your time.
if the only thing using time is the countdown and i have a Thread.Sleep(50) it should be fine ?
its 1 am so im tired
so not rlly taking in much
tmr ill come back through and laern it all
are you good at coding c# ? cause i have this lgoic error that i just cant fix no matter what i try
I am as good as you are.
I may just have fixed more things with carefully reading along the way.
can you take a look at my error and see if you can fix ?
I have to be honest and say no.
I can look into the code but before I know how to fix it I am 2 hours into the future.
It would be a waste of both our sleep.
So. Can we pick this up again tomorrow?
sure
ill send the code and the error so if you got free time ya can look at it tmr
https://paste.mod.gg/ygzzctyynomz/0
after pressing enter then spcea and hold space it registers 2 input but i just wnat it to take 1 input and then it wont take another input until the spacebar has been releasaed annd repressed
BlazeBin - ygzzctyynomz
A tool for sharing your source code with the world!
in the 3rd like it says private Timer - is timer a data type ?
also whats teh event handler ?
as in waht does it mean by eventhandler
ping me when your on
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.@OCT'🥚EntireTeamIsBabies!
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.