View Full Version : Multiple timer actions
yosik
03-21-2004, 10:02 AM
I need to setup various actions that will take place based on the user clicking on buttons. These actions are time related.
Ex: 2 objects +2 buttons.
when user clicks on button1, object1 moves off screen (timer with object position incrmenting).
Same with object2.
How can I call a different onTimer trigger for each button?
Thanks
Yossi.
P.s. I don't want AMS to be running constantly in the background a "onTimer" bunch of actions. I think it is inneficient programming technique.
TJ_Tigger
03-21-2004, 12:33 PM
I have thought about this as well. My thought was that you could have on timer started but every time it happens you could use two conditional statemements that increment a number, if the number is one then your timer has gone off one time if it is 5 then your timer has gone off 5 times. You can take actions based on this.
I havent actually tried this but it is the first thought I had on accomplishing what I wanted.
Page.StartTimer(1000);
timercounter = 0
On Timer
timercounter = timercounter + 1
Button.SetPos("button1", xpos-5, ypos);
if timercounter == 2 then
timercounter = 0;
Button.SetPos("button2", xpos2 - 5, ypos2);
end
Or something like that anyway. This will move button 1 every second and button2 every two seconds.
I will play with it some more in an actual project and see what I can come up with.
Tigg.
Corey
03-21-2004, 02:10 PM
P.s. I don't want AMS to be running constantly in the background a "onTimer" bunch of actions. I think it is inneficient programming technique.
I think there may be a misinterpretation of this issue. Running a timer in the background is no problem and many apps which you are currently using no doubt do that, or something similar in the course of running. A background timer for today's computers is far from inefficient. That's what it's there for. :)
Just FYI anyhow.
There's no harm at all in have a timer going. The only issue might arise if you have the timer checking lots and lots of stuff like ten times per second or whatever. But if you're sensible and keep the code to a minimum, you will have no trouble at all.
Corey Milner
Creative Director, Indigo Rose Software (http://www.indigorose.com)
yosik
03-21-2004, 03:04 PM
Thanks TJ and Corey (and Rhosk).
TJ, what I want is a separate control for different objects. Your solution doesn't quiet do it. Thanks though.
Corey, my impression is that if I have something working all the time (even once every x milliseconds), perfomance would be affected.
I am trying to work something out like having a condition in the onTimer event which is dependent on a variable value received via the button. Then this or that part of code would be run, depending on the variable value.
I am not there yet though.
Yossi
Corey
03-21-2004, 03:09 PM
Yossi, not at all. It's a simple timer, there are so many things happening "per second" on a modern computer that it's amazing.
For example, you watch video right? Well I can guarantee you it takes a *whole lot* more computer to fully render 15 frames per second at 640 X 480 than it ever will to run a tiny counter. :)
Trust me, running a small timer is definitely not an issue for any modrn computer, not even close. :)
Corey Milner
Creative Director, Indigo Rose Software (http://www.indigorose.com)
yosik
03-21-2004, 03:14 PM
I hear ya, Corey. Thanks
Yossi
Corey
03-21-2004, 03:28 PM
Just FYI Yossi, I'm a slow adapter usually, i.e. you notice we only added DHTML menus to our site here now in 2004 whereas some folks have been doing it since 2000. So I'm totally with you on this one, it took me a while to get used to running timers and not worrying about it. I think for me, my history in Flash is what helped though, some of my Flash movies were firing dozens of instructions per second with corresponding animations and they seem to be OK, so that gives me confidence in page timers.
I tested them lots, and I haven't found a slow timer yet, but then again, if you really bog one down, in theory it could get slow eventually.
You could always build in an inertia state where, if nothing requiring the timer is present, it stops - and then restarts as needed. Just a thought.
Corey Milner
Creative Director, Indigo Rose Software (http://www.indigorose.com)
yosik
03-21-2004, 03:44 PM
Good idea. Help me here. how do you restart a ontimer event? and I don't mean by clicking or reloading a page.
Yossi
Corey
03-21-2004, 03:53 PM
Hi. Well you have
Page.StartTimer();
and
Page.StopTimer();
Which you can use freely to toggle a timer. When it is off, nothing in the timer area will occur, when it's on, everything in that area will occur according to the interval you set.
For example:
Page.StartTimer(1000);
Would set it to fire once per second whereas
Page.StartTimer(100);
would be ten times per second, and so forth... Which is another point, for many types of functionality you only need to check something once per second, which is very little CPU load, so try to use the largest increment which suits your needs. But this is to be kept in perpspective too, i.e. to check a variable value ten times per second is also very little load on the CPU, so you be the judge...
Corey Milner
Creative Director, Indigo Rose Software (http://www.indigorose.com)
yosik
03-21-2004, 04:00 PM
Corey, I didn't explain myself well enough.
If onTimer is used in a Page.onShow event, it is launched only once, unless you reload the page.
You can use a onTimer event with a button.
I was wondering how do you launch a ontimer event (which would, inturn, check and act based on a time interval)?
Yossi
Corey
03-21-2004, 04:06 PM
I'm not sure I understand. Here's how I see it:
You have a page timer. You can start and stop this page timer freely using the actions listed above. Any actions in the onTimer event will fire according to these. To toggle these on and off I reccomend using conditionals or variables.
Feel free to post a sample project or give details of a sample scenario, maybe I'll be able to understand that better.
Corey Milner
Creative Director, Indigo Rose Software (http://www.indigorose.com)
yosik
03-21-2004, 04:17 PM
ok, scenario:
I have an image on my page.
if the user doesn't click on anything, after, let's say 20 seconds, this image starts pulsing (alpha channel value and size values change) . The pulsing is done with an OnTimer action which sets the rythm. Above/before that, there is another ontimer action which is the one checking this 20 second waiting period before launching the second ontimer action.
A bit muddy, but I hope you got my meaning.
Thanks for your time, Corey.
Yossi
Corey
03-21-2004, 04:40 PM
Hi. OK:
1. We start a timer, set to fire once per second:
Page.StartTimer(1000);
2. We set the button to set a variable OnClick, i.e. wait = 1;
3. In the Timer Event area we add some actions:
a) an action to increment the variable wait once per second, i.e. wait = wait + 1;
b) an if statement to check and see if wait = 20 and if it does, initiate the image effect.
Hope that helps, unless I'm still missing the point, wouldn't be the first time. :wow
Corey Milner
Creative Director, Indigo Rose Software (http://www.indigorose.com)
yosik
03-22-2004, 01:17 AM
Sorry for the delay in answering, I do sleep sometimes (unlike some of you, guys....;) )
Yes, it does help. Thanks Corey.
I am trying to fit my conception of timeline based events or sequencial events in AMS and here lies the problem. Each program has its own "frame of mind". I see that the onTimer event, albeit great in itself isn't a fully time oriented trigger.
There are almost always some ways or workarounds to get to where to want to go, but it would be nice to have an onTimer trigger attached to objects. That way each onTimer can be independent.
Thanks a lot, Corey. Great supprot.
Yossi
Stefan_M
03-22-2004, 01:22 AM
Little Demo.
Scripts found in
Project/Actions
On StartUp (predefined Variables)
Page:
On Timer (Code for waiting and pulsing)
On Preload (Start Timer)
Buttons:
On CLick (Set Variable)
Stefan
Corey
03-22-2004, 01:27 AM
Hi. The main thing to remember though is that you can still do as many independent things as you want, you're just doing them via one master timer. It's rare you will need to do anything more than ten times per second so that's a good general rule of thumb.
Anyhow you should add "object timers" to the suggestion forum if you get a sec, it's a good idea. :)
Corey Milner
Creative Director, Indigo Rose Software (http://www.indigorose.com)
yosik
03-22-2004, 03:36 AM
Thanks, Stefan.
Explain things to me slowly and I catch them very quickly....:)
It finally got thru to me. The "counter" value is what was missing in my head.
You helped...Thanks
Yossi
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.