Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?
You are not logged in.
So I would like to do a countdown, when someone hit the coin. I made the timer (with interval of 1000) and I made the coin script. When someone hits the coin, he will get the crown, get +1 win, but then nothing happens. What did I do wrong?
Coin script:
if (m.Type == "c")
{
string username = users[m.GetInt(0)];
if (coinpickedup == 0)
{
addWins(users[m.GetInt(0)], +1);
con.Send("say", "/pm " + username + " Nice job! You won!");
say("The coin has been hit by: " + username + " You have 10 seconds to pick up the coin! But that is not counted as a win.");
con.Send("say", "/givecrown " + username);
coinpickedup = 1;
timeLeft = 10;
timer1.Enabled = true;
}
}
Timer script:
public void timer1_Tick(object sender, EventArgs e)
{
if (timeLeft > 0)
{
timeLeft = timeLeft - 1;
say("You have got " + timeLeft + " seconds left");
}
else
{
con.Send("say", "/reset");
coinpickedup = 0;
timer1.Enabled = false;
}
}
Offline
Use timer.Elapsed, don't really know what tick does (too lazy to google right now) Just know that you need to you elapsed.
I assume you know how to assign the timer's .elapsed function to one that you've made?
Offline
Use timer.Elapsed, don't really know what tick does (too lazy to google right now) Just know that you need to you elapsed.
I assume you know how to assign the timer's .elapsed function to one that you've made?
Yes, thanks
Offline
You could create another thread that sleeps for that x minutes.
Edit:
using System.Threading;
Thread thread = new Thread(delegate() {
Thread.Sleep(x * 60000); // 1 minute is 6 * 10 ^ 4 milliseconds
connection.Send("say", "/reset");
}));
thread.Start();
Everybody edits, but some edit more than others
Offline
You could create another thread that sleeps for that x minutes.
Edit:
using System.Threading; Thread thread = new Thread(delegate() { Thread.Sleep(x * 60000); // 1 minute is 6 * 10 ^ 4 milliseconds connection.Send("say", "/reset"); })); thread.Start();
-1 Using Thread.Sleep is much more unreliable compared to timers, and: why reinvent the wheel?
I have never thought of programming for reputation and honor. What I have in my heart must come out. That is the reason why I code.
Offline
Use timer.Elapsed, don't really know what tick does (too lazy to google right now) Just know that you need to you elapsed.
I assume you know how to assign the timer's .elapsed function to one that you've made?
I ask you to cite or something. I've always seen Tick used, it makes sense, and it works.
http://stackoverflow.com/questions/1013 … tick-event talks about different timers... perhaps you were referring to something else? This code looks like winform auto generate!
You could create another thread that sleeps for that x minutes.
interesting approach. Probably should interject a suggestion per keeping track of the thread... in case it needs to be dropped or something.... not sure what to tell you I guess. I'd probably do this... because I'm too lazy to make timers in the editor.
-1 Using Thread.Sleep is much more unreliable compared to timers, and: why reinvent the wheel?
and now the politically correct people make the entrance
http://stackoverflow.com/questions/8815 … so-harmful
we really don't need the precision, but quiescent threads are apparently a problem. I guess waithandles look nice
Offline
den3107 wrote:Use timer.Elapsed, don't really know what tick does (too lazy to google right now) Just know that you need to you elapsed.
I assume you know how to assign the timer's .elapsed function to one that you've made?
I ask you to cite or something. I've always seen Tick used, it makes sense, and it works.
http://stackoverflow.com/questions/1013 … tick-event talks about different timers... perhaps you were referring to something else? This code looks like winform auto generate!
He used the winforms timer, I don't remember exactly where I read it, but the System.Timers.Timer object is preferred over the System.Windows.Forms.Timer object.
Processor wrote:-1 Using Thread.Sleep is much more unreliable compared to timers, and: why reinvent the wheel?
and now the politically correct people make the entrance
http://stackoverflow.com/questions/8815 … so-harmful
we really don't need the precision, but quiescent threads are apparently a problem. I guess waithandles look nice
As the url stated (kudos to the research), it's simply a waste of your memory and takes a terrible amount of time (for a computer) to create and destroy, as for that the sleep function simply isn't accurate, but indeed, that accuracy isn't very noticeable in this context.
Now the waste of memory might also not be a big problem in the current context, but imagine Zumza were to want to do programming for a living later on, it'd be best to learn the correct way as soon as possible, since it's harder and harder to do stuff different the older you become.
Offline
Offline
takes a terrible amount of time (for a computer)
200,000 cycles = 0.083ms on a 2.4GHz CPU. Oh the horror.
People should lower their standards. While it's fun to imagine we're all professional programmers, it's not stack overflow and it's not commercial software.
Suggest [with code] a few simple alternate solutions and let OP decide what method to use, instead of raging at unnoticeable time intervals, tiny memory usages and each others' suggestions.
One bot to rule them all, one bot to find them. One bot to bring them all... and with this cliché blind them.
Offline
den3107 wrote:takes a terrible amount of time (for a computer)
200,000 cycles = 0.083ms on a 2.4GHz CPU. Oh the horror.
People should lower their standards. While it's fun to imagine we're all professional programmers, it's not stack overflow and it's not commercial software.
Suggest [with code] a few simple alternate solutions and let OP decide what method to use, instead of raging at unnoticeable time intervals, tiny memory usages and each others' suggestions.
As I stated earlier, it's best to learn the correct way sooner or later (since myself I obviously too am far from any grade of programmer).
the thing is, when it's easy to do it in another more efficient way with a little research (where sometimes that method might even be easier!), it's best to just do that little research.
P.S. I did give an answer to the OP which he said worked.
Offline
"yes thanks"
Either the person is staunchly incapable of writing messages of appreciation (or messages at all), or we haven't implemented a fixed solution.
Even if we have solved it, the implementation is still exogenous.
Offline
This topic became more an "Fast write and easy to maintain code VS Highly optimised and hard to interpret code" topic.
It is a great pleasure to know that your code is an art piece. This is one of the satisfaction for being a programmer.
I usually prefer writing something in between this two parts when I share the code with someone else.
Highly optimised code depends very much on what the final algorithm must do. By example maybe @Kikikan doesn't need a timer.
Everybody edits, but some edit more than others
Offline
[ Started around 1732367503.4253 - Generated in 0.079 seconds, 12 queries executed - Memory usage: 1.56 MiB (Peak: 1.74 MiB) ]