Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   Countdown Timer (https://forums.graalonline.com/forums/showthread.php?t=134265168)

Hezzy002 12-07-2011 01:41 AM

setTimer is frame-based, not time-based.

Gunderak 12-07-2011 02:53 AM

setTimer works in a DBNPC, are you sure it's frame based?

DustyPorViva 12-07-2011 02:58 AM

Quote:

Originally Posted by Hezzy002 (Post 1676666)
setTimer is frame-based, not time-based.

It is time-based... a timer of 0.05 triggers every 0.05 seconds. Graal is 20fps, meaning it's running at 20 frames a second, so 1 second / 20 frames = 0.05, or the lowest timeout possible.

fowlplay4 12-07-2011 03:08 AM

Quote:

Originally Posted by Gunderak (Post 1676676)
setTimer works in a DBNPC, are you sure it's frame based?

Frame-based in the sense that the timeout value decreases by (1 / Max FPS). On the server-side the Max FPS is 10, and on the client-side it's 20 (Like Dusty mentioned).

That is why it's useless to set timeouts lower than 0.1 on the server-side and 0.05 on the client-side. (Depending on the application you should be using the highest or no timeout at all if possible).

Play with this script:

PHP Code:

function onCreated() {
  
this.test timevar2;
  
this.speed 0.05;
  
setTimer(this.speed);
}

function 
onTimeout() {
  echo(
timevar2 this.test);
  
this.test timevar2;
  
setTimer(this.speed);


Both 0.05 and 0.1 will return similar values.

Gunderak 12-07-2011 06:28 AM

Ah I see.
So it's not actually controlled by when the game enters a new frame.
I was confused for a bit there lol.

Hezzy002 12-07-2011 04:48 PM

Quote:

Originally Posted by DustyPorViva (Post 1676677)
It is time-based... a timer of 0.05 triggers every 0.05 seconds. Graal is 20fps, meaning it's running at 20 frames a second, so 1 second / 20 frames = 0.05, or the lowest timeout possible.

I don't mean frame-based in the sense that you input frame values, I mean that it doesn't compare against the computer's clock; it just subtracts .05 from a value each frame and runs the function when it hits zero, and thus is less reliable for anything that's time-based instead of frame-based.

callimuc 12-07-2011 05:27 PM

Maybe itīs just me, but why not use this check?
PHP Code:

function onTimeout() {
  if (
this.secondsleft <= 0) {
    
//stuff
  
}
  
settimer(1);



scriptless 12-26-2011 08:20 PM

Question, you have 2 timeouts. One for actually counting down, and one for showing the time. Correct me if I am wrong but wouldn't it be better to just calculate the time with timevar/timevar2 in the timeout to show the variable?

Pelikano 01-24-2012 04:34 PM

Quote:

Originally Posted by scriptless (Post 1679556)
Question, you have 2 timeouts. One for actually counting down, and one for showing the time. Correct me if I am wrong but wouldn't it be better to just calculate the time with timevar/timevar2 in the timeout to show the variable?

Didn't read through the posts, but you can't "count time" inside a timeout anyway, because if you set the timeout to 0.1, it doesn't mean that it will actually be called after 0.1 seconds, it may be called after 0.5 seconds depending on the performance...

Crow 01-24-2012 04:39 PM

Quote:

Originally Posted by Pelikano (Post 1682610)
Didn't read through the posts, but you can't "count time" inside a timeout anyway, because if you set the timeout to 0.1, it doesn't mean that it will actually be called after 0.1 seconds, it may be called after 0.5 seconds depending on the performance...

If you're setting the timer to 0.1, it will be called approximately 0.1 seconds later. You can count time with the use of a timeout, but the longer you are doing this, the less accurate it will get.

Pelikano 01-24-2012 06:57 PM

Quote:

Originally Posted by Crow (Post 1682612)
If you're setting the timer to 0.1, it will be called approximately 0.1 seconds later. You can count time with the use of a timeout, but the longer you are doing this, the less accurate it will get.

it will be called @ the next frame when your timer time is over, which means that if a frame takes 0.5 second due to lag or anything your counter will be wrong

Crow 01-24-2012 08:20 PM

Quote:

Originally Posted by Pelikano (Post 1682615)
it will be called @ the next frame when your timer time is over, which means that if a frame takes 0.5 second due to lag or anything your counter will be wrong

Duh.

scriptless 01-24-2012 09:56 PM

Quote:

Originally Posted by Pelikano (Post 1682610)
Didn't read through the posts, but you can't "count time" inside a timeout anyway, because if you set the timeout to 0.1, it doesn't mean that it will actually be called after 0.1 seconds, it may be called after 0.5 seconds depending on the performance...

You can, but it's not as accurate. That is why I asked, would it not be better to just use timevar/timevar2?

Mark Sir Link 01-24-2012 11:49 PM

Quote:

Originally Posted by Gunderak (Post 1676465)
Well I'm going to have to disagree with you there.
"Does not make it harder to read".
If anything it defines what you are assigning the variable to clearer.
And it does not change the way the script functions at all.

is this real life


All times are GMT +2. The time now is 06:58 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.