Jump to content
  • 0

Best way to set a chronometerw


badneko

Question


  • Group:  Members
  • Topic Count:  17
  • Topics Per Day:  0.00
  • Content Count:  37
  • Reputation:   1
  • Joined:  06/09/14
  • Last Seen:  

Something like start time, then stop it and show the time has passed.

 

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

  • Group:  Forum Moderator
  • Topic Count:  33
  • Topics Per Day:  0.01
  • Content Count:  1268
  • Reputation:   382
  • Joined:  02/03/12
  • Last Seen:  

Something like start time, then stop it and show the time has passed.

All the types of timers have different unique advantages but the best in terms of utility and performance is the built in timer... If that's even what you're asking... If you just want to show the amount of time that's passed between a distinct time-frame variables are the best way of doing that.

startnpctimer; //Starting the timer attached to the npc.
.start = gettimetick(2); //Saving the start time to my npc variable.
end;

OnTimer10000: //Calling the label when 10 seconds have passed.
stopnpctimer; //Destroying the timer.
.end = gettimetick(2); //Saving my ending time.

.difference = .end - .start; //Calculating the time that has passed.

dispbottom .difference + " seconds have passed."; //Spilling the output.
Link to comment
Share on other sites

  • 0

  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10015
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

@Skorm 

i believe your method is redundant.

 

why not just pick 

initnpctimer + stopnpctimer + getnpctimer

or

start gettimetick - end gettimetick

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  17
  • Topics Per Day:  0.00
  • Content Count:  37
  • Reputation:   1
  • Joined:  06/09/14
  • Last Seen:  

Thanks guys!. And now how i can avoid the "there is no player attached error"?

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.00
  • Content Count:  2044
  • Reputation:   682
  • Joined:  10/09/12
  • Last Seen:  

if you are writing something like algorithm script, you can just use gettimetick(0)

.@start = gettimetick(0);
callfunc "F_SomeAlgorithm";
dispbottom "time used -> "+( gettimetick(0) - .@start ) +" mili-seconds";

you can find various algorithm like sorting algorithm in this topic

http://herc.ws/board/topic/4321-help-me-improve-this-merge-sort-algorithm/

or shuffle algorithm in this topic

https://github.com/HerculesWS/Hercules/pull/872

 

but if you are just to check how much time it click on the npc, gettimetick(0) cannot be use here because it will go negative at 24th day

has to use npctimer

 

*check and see properly did I use rathena test server ? OK*

 

I think there is a bug, yes, both hercules and rathena, I tested both

prontera,158,185,5    script    dfgdgdfg    1_F_MARIA,{
    attachnpctimer; // comment this line, it shows the timer
    initnpctimer;
    sleep2 1000;
    stopnpctimer;
    dispbottom getnpctimer(0);
    end;
}

if the attachnpctimer is leave on, the timer always show 0, but when I remove it, which makes it attach to npc, the timer will start showing ...

 

for the time being, stick to gettimetick(0) ...

  • Upvote 1
Link to comment
Share on other sites

  • 0

  • Group:  Forum Moderator
  • Topic Count:  33
  • Topics Per Day:  0.01
  • Content Count:  1268
  • Reputation:   382
  • Joined:  02/03/12
  • Last Seen:  

@Skorm 

i believe your method is redundant.

 

why not just pick 

initnpctimer + stopnpctimer + getnpctimer

or

start gettimetick - end gettimetick

 

Please use your head. You say my method is redundant and then tell him to use commands that function in the exact same way. For clarity, yes he is starting it with a different command and checking it in a different way but they both work on the same timer system within the source.

 

What I was trying to explain is to use NPC TIMERS... Instead of sleep or loops. x_x

 

And to save timestamps to variables!

 

But yeah thanks for insulting staff. You're a fantastic Global Moderator (Keeping the peace).

 

(If you reply to this message, Emistry, I will not answer. I'm not trying to start a war I'm just pointing out the obvious.)

 

if you are writing something like algorithm script, you can just use gettimetick(0)

.@start = gettimetick(0);
callfunc "F_SomeAlgorithm";
dispbottom "time used -> "+( gettimetick(0) - .@start ) +" mili-seconds";

you can find various algorithm like sorting algorithm in this topic

http://herc.ws/board/topic/4321-help-me-improve-this-merge-sort-algorithm/

or shuffle algorithm in this topic

https://github.com/HerculesWS/Hercules/pull/872

 

but if you are just to check how much time it click on the npc, gettimetick(0) cannot be use here because it will go negative at 24th day

has to use npctimer

 

*check and see properly did I use rathena test server ? OK*

 

I think there is a bug, yes, both hercules and rathena, I tested both

prontera,158,185,5    script    dfgdgdfg    1_F_MARIA,{
    attachnpctimer; // comment this line, it shows the timer
    initnpctimer;
    sleep2 1000;
    stopnpctimer;
    dispbottom getnpctimer(0);
    end;
}

if the attachnpctimer is leave on, the timer always show 0, but when I remove it, which makes it attach to npc, the timer will start showing ...

 

for the time being, stick to gettimetick(0) ...

 

Thank you Annie for offering depth into your answer, and avoiding any kind of arbitrary arguments. Also thank you for finding a bug in Emistry's "Superior" method.

 

You really are the best.

Link to comment
Share on other sites

  • 0

  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10015
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

@Skorm

hmm, I am not exactly sure when did I insult you ?  

 

your method,

OnTimer10000 has clearly told the script it's already 10 seconds passed.

why you still need to store the start and end time ? and recalculate the difference, which is also 10 seconds .

it's unnecessary and redundant method in scripts.

 

well, everyone have their own style, I am not saying that my method are so-called "Superior" here, but i defnitely believe it's could be enhanced.

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.00
  • Content Count:  2044
  • Reputation:   682
  • Joined:  10/09/12
  • Last Seen:  

ok both of you please stop ...

if I actually see this in hercules, I'll invisible the post, and send a group PM to both of you to settle this issue privately ...

 

both of you are respectable scripters in rathena, along with Capuche, Euphy , Brian ... and some others

despite the difference in emulator we are using, there is no need to create whatever drama that can raise the tension between all of us

 

anyway ..

I just found this in the source code ... its a TODO

https://github.com/rathena/rathena/blob/master/src/map/npc.c#L780

try report this issue to get this fix

 

EDIT:

and this is gettimetick(0) method, which will go negative on 24th day and may create bug

prontera,158,185,5    script    kjhfksdjf    100,{
    if ( @timeon ) {
        dispbottom "time used -> "+( gettimetick(0) - @start ) +" mili-seconds";
        @start = 0; // clear the var
    }
    else
        @start = gettimetick(0);
    @timeon ^= 1;
    end;
}
Edited by AnnieRuru
  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...