ID:144592
 
Code:Time for turn.
mob/proc/Count()
CountDown()
proc/CountDown()
CountDown=0
CountDown+=1
if(seconds<=0) {minutes--;seconds+=60}
time="[minutes] == Minutes || [seconds] == Seconds"
sleep(10)
seconds-=1
time="0 == Minutes || 0 == Seconds"
while(minutes>0||seconds>0)
CountDown()
usr.RefreshTime(usr)
usr.End_Player_Turn(usr)
mob/proc/RefreshTime()
minutes=2
seconds=0
var/minutes=2
var/seconds=0
var
CountDown=0
time="[minutes] == Minutes || [seconds] == Seconds"


Problem description:Every time you refresh and count it gets faster I dont wnat that can you help me fix this coding please.

Step one would be to replace "usr" with "src" in all procs.
In response to CuriousNeptune
I see people use that to answer just about any question, yet from my experience, doing so is useless. I've used usr and src interchangably in procs and nothing has ever gone wrong (for that reason).

Can you explain to me why it's so important to use src?
In response to FireEmblem
Neptune is being stupid. You should NOT replace usr with src in procs. You should replace usr with what should be in there in the first place.

FireEmblem, usr is ALWAYS incorrect in procedures, unless it's a psuedoverb, like all the Click() and Mouse() procedures.

Nothing has ever gone wrong because you haven't been looking. Just wait until you have something mildy interesting happening.. suddenly, FOOM! Weird runtime errors that are difficult to debug - all because you've been abusing usr. It's not useless in the least. Always treat usr with a grain of salt, because it's likely to not be what you think it is.

Just remember: usr Unfriendly
In response to Jp
Alright, thanks. I guess it's because I've been using it for pseudoverbs and never anything really complex.

Now I know.
Your countdown sucks. You should use this:

var/countdown
proc/Countdown()
countdown=1200 //two minute countdown
while(countdown>0)
countdown-=5
sleep(5)
//do end-turn stuff etc. here

mob/verb
check_countdown() //checks the time of the countdown
var
seconds=round(countdown/10) //get the seconds from the countdown and round it up
minutes=round(seconds/60) //get the minutes from the countdown and round it up
for(var/i=minutes,i>0,i--)seconds-=60 //for every minute decrease seconds by 60

var/time="You'll have to wait "
if(minutes>0)time+="[minutes] minutes and "
time+="[seconds] seconds."

src<<time
start_countdown() //starts the countdown if it's not started
if(!countdown)spawn()Countdown()


Doing it like this will make for a much more robust code, and it only uses a single variable.

The countdown is not accurate. This is intentional, as not to lag the system with the countdown. It should be somewhat accurate.

Keep in mind that the <code>Countdown()</code> proc, as well as your own <code>CountDown()</code> proc, is global, and not on a mob-per-mob basis.
In response to Android Data
How would I make it mob for mob. I have it just doing it for the two players in a duel.
In response to KillerGrand
Do not rely on us to provide you with free code snippets everytime you ask. You should read the DM Guide.




KillerGrand wrote:
How would I make it mob for mob. I have it just doing it for the two players in a duel.

One way of doing this is to make the <code>Countdown()</code> proc a mob proc, and make the <code>countdown</code> variable a mob variable. If you just do that, chances are that the starting and viewing of countdowns will also still work like they should. But it might not be the best solution.
In response to Jp
Jp wrote:
Neptune is being stupid. You should NOT replace usr with src in procs. You should replace usr with what should be in there in the first place.


So, by default, what should be there in the first place?
In response to Jp
Jp wrote:
unless it's a psuedoverb, like all the Click() and Mouse() procedures.

Except in their respective client procs (client/Click()), when you really should be using client.mob.
In response to CuriousNeptune
Depends on context. In some cases, such as, say, mob/Login(), it should be src. (Usr is 'safeish' in mob/Login(). As long as players can't change mobs WITHIN the game, it should always be the same as src. But really, it shouldn't be there)

But in movement procedures, for example, Entered(), it should be an argument passed to the procedure.
In response to Jp
Jp wrote:
But in movement procedures, for example, Entered(), it should be an argument passed to the procedure.

...where src is the object that was Entered(). ;)

Hiead
In response to Android Data
That's an improvement, but much better would be not to use a loop at all, and instead use world.time.

Lummox JR
In response to Android Data
Android Data wrote:
Your countdown sucks. You should use this:

>   check_countdown() //checks the time of the countdown
> var
> seconds=round(countdown/10) //get the seconds from the countdown and round it up
> minutes=round(seconds/60) //get the minutes from the countdown and round it up
> for(var/i=minutes,i>0,i--)seconds-=60 //for every minute decrease seconds by 60


The for() loop shouldn't be there.
seconds -= minutes * 60


Hiead
In response to Hiead
Ah, yes. My math sucks. You should use his.