PDA

View Full Version : How can i make 2 Timer in page


ibrahimalsrogy
02-06-2006, 08:02 PM
how can i make 2 timar :

ex: Page.StartTimer(5000); && Page.StartTimer(200);
in the same page, how??????????

Corey
02-06-2006, 08:14 PM
Hi, simply find the lowest common denominator between the various timings you need, and then treat those as units. :yes

So for example, let's say I have one event which repeats every second and one which repeats every second and a half. Then I would simply set the timer to increment twice per second and track each event accordingly. :yes

ibrahimalsrogy
02-06-2006, 08:29 PM
sorry i can't understand , can u make a sample please

Worm
02-06-2006, 08:46 PM
Here's an example that may help you out.
http://www.indigorose.com/forums/showpost.php?p=71462&postcount=19

yosik
02-07-2006, 12:03 AM
Another way to do that, especially if you cannot find a "common denominator" and you want something different happening in your timer action, is to use a bunch of "if", maybe even bundling them all inside a global function.
You would then set a relevant variable when launching the pagetimer so that when the PageTimer is invoked, it will run the relevant code based on that variable.
BTW, this is where an ObjectTimer would come handy....

Yossi

Corey
02-07-2006, 12:21 AM
FWIW it's fairly easy to create code based object timers with the existing system also. :yes

azmanar
02-07-2006, 02:30 AM
Another way to do that, especially if you cannot find a "common denominator" and you want something different happening in your timer action, is to use a bunch of "if", maybe even bundling them all inside a global function.
You would then set a relevant variable when launching the pagetimer so that when the PageTimer is invoked, it will run the relevant code based on that variable.
BTW, this is where an ObjectTimer would come handy....

Yossi

Object Timer ?? Wow... do we have it?

Corey
02-07-2006, 02:41 AM
No, there's no such thing per se, but it would be easy to write one. It all depends on what you're trying to time.

azmanar
02-07-2006, 03:02 AM
No, there's no such thing per se, but it would be easy to write one. It all depends on what you're trying to time.

Ahhh....ok.

Sometimes, at specific timings, we need to change object content, Label Text or Image for instance.

This is suitable for making simple games for children. They type correct spellings into an input box at a given time based on an Image and an Anagram Label before another Image and Anagram appears.

Like you say, it is easily coded. But if there is an Object Timer, it would be fantastic - like a non-linear tool or storyboard of objects.

Corey
02-07-2006, 03:05 AM
Yes a separate "On Timer" event for every object would be handy for some stuff. You should add that to the suggestions forum. :yes

TJS
02-08-2006, 08:50 AM
sorry i can't understand , can u make a sample please

I just did this for a pong-like game. I needed one timer to control the refresh rate for moving objects (like the ball and paddles). The other timer controls the delay of the computer controlled paddle (otherwise it is impossible to win).

To do this I start the timer for the current page and define the delay(s) I intend to use (I do this On Key, but you could do this On Show or anywhere else except On Timer):

Page.StartTimer(10);
g_OppDelay = 3;

Now I set your preferred actions On Timer event for the page like moving the ball:

-- Move the ball
Image.SetPos("imgBall", t_BallPos.X + g_XBallMotion, t_BallPos.Y + g_YBallMotion);

For the actions that I want to run less frequently, I setup a counter to that triggers the action and resets when the interval is reached:

-- Setup a counter to control delays on the opponent's paddle
if g_TimeCount > g_OppDelay then
g_TimeCount = 0
else
g_TimeCount = g_TimeCount + 1;
end

-- Check to see if the delay has expired and if so, allow the opponent to check which direction it should be going
if g_TimeCount == g_OppDelay then
t_OppPos.X = Image.GetPos("imgOpp");
if t_OppPos.X <= g_WestWall and g_XBallState < 0 then
g_XOppState = 0;
elseif (t_OppPos.X + g_PaddleSize) >= g_EastWall and g_XBallState > 0 then
g_XOppState = 0;
else
if (t_OppPos.X + (g_PaddleSize / 2) - t_BallPos.X + (g_BallSize / 2)) > 0 then
g_XOppState = -1;
elseif (t_OppPos.X + (g_PaddleSize / 2) - t_BallPos.X + (g_BallSize / 2)) < 0 then
g_XOppState = 1;
else
g_XOppState = 0;
end
end
end

I suspect that my example is not exactly (your probably working on something more productive :)) to what you are trying to accomplish, but I think the concept would be the same.

TJS
02-08-2006, 10:15 AM
sorry i can't understand , can u make a sample please

I just did this for a pong-like game. I needed one timer to control the refresh rate for moving objects (like the ball and paddles). The other timer controls the delay of the computer controlled paddle (otherwise it is impossible to win).

To do this I start the timer for the current page and define the delay(s) I intend to use (I do this On Key, but you could do this On Show or anywhere else except On Timer):

Page.StartTimer(10);
g_OppDelay = 3;

Now I set your preferred actions On Timer event for the page like moving the ball:

-- Move the ball
Image.SetPos("imgBall", t_BallPos.X + g_XBallMotion, t_BallPos.Y + g_YBallMotion);

For the actions that I want to run less frequently, I setup a counter to that triggers the action and resets when the interval is reached:

-- Setup a counter to control delays on the opponent's paddle
if g_TimeCount > g_OppDelay then
g_TimeCount = 0
else
g_TimeCount = g_TimeCount + 1;
end

-- Check to see if the delay has expired and if so, allow the opponent to check which direction it should be going
if g_TimeCount == g_OppDelay then
t_OppPos.X = Image.GetPos("imgOpp");
if t_OppPos.X <= g_WestWall and g_XBallState < 0 then
g_XOppState = 0;
elseif (t_OppPos.X + g_PaddleSize) >= g_EastWall and g_XBallState > 0 then
g_XOppState = 0;
else
if (t_OppPos.X + (g_PaddleSize / 2) - t_BallPos.X + (g_BallSize / 2)) > 0 then
g_XOppState = -1;
elseif (t_OppPos.X + (g_PaddleSize / 2) - t_BallPos.X + (g_BallSize / 2)) < 0 then
g_XOppState = 1;
else
g_XOppState = 0;
end
end
end

I suspect that my example is not exactly what you are trying to accomplish (you're probably working on something more productive :)) , but I think the concept would be the same.