PDA

View Full Version : Important method NOT included, Timer


usernameCasper
11-22-2006, 02:43 AM
Hey folks,

I have one important message IMO.
I've searched over 4 hours for the method for Time(r)s or something like that.
Havent found anything, except the On Timer event, called by Page.StartTimer
Isnt there a way to put the timers in a object for example.
So if clicked on a button is true, then timer will start in a Paragraph.
If the timer reach 5 seconds, than add "hallo" in ParagraphText.
If the timer reach 5 seconds, than add "hallo folks" in ParagraphText.
In my testapplication I got 3 objects that 'startTimer' on the 'On Time'.
So if object 1 reaches his limit, it will stopTimer, but object 2 and 3 needs to be active in the On Time.

Maybe a suggestion to make a method called Wait or Timer or Timed, etc. for AMS update or AMS 7 ?? For scripters, this is an important feature !!

Maybe I haven't found the method, but i searched everywhere to solve this...
My script on 'On Timer' (related on which page, all objects on Page1) is huge.

Sollutions or idea's are very welcome and will be warmed received !!

Kind Regards,
Casper

usernameCasper
11-22-2006, 10:43 AM
Please let me know ...
There must be someone with some ideas...
Thanks in advance

holtgrewe
11-22-2006, 06:15 PM
Here's what I use for Page timers.

I normally set the page timer "on Preload" Page.StartTimer(4000); -- this timer will fire every 4 seconds

Then on the page script tab "on Timer", through scripting, you can do whatever you want to the objects on the page (every 4 seconds), or whatever duration you want to set.

Search "timer" for some very good examples of using the Page Timer, and techniques for setting up multiple timers on a page.


I hope this helps.

Intrigued
11-22-2006, 06:50 PM
Examples via way of using the Search in the forums here:

http://www.indigorose.com/forums/showpost.php?p=80951&postcount=9

http://www.indigorose.com/forums/showpost.php?p=37648&postcount=3

http://www.indigorose.com/forums/showpost.php?p=30027&postcount=2

And here is something offtopic just to check out. It the product of three people's coding efforts:

http://www.amsuser.com/ams/examples/EPiano-others-JimS&Protocol&Intrigued-team.exe

(something to get our idea-juices flowing if not anything else) ;)

usernameCasper
11-23-2006, 02:18 AM
thanks for the replies, but one problem.
I know how to fire a timer (refresher), I changed my whole app on this timer event, although it takes a load of time to set all changes to that.
I take a startTimer, interval of 250ms, then in the On Timer event i take if lalala => 2000 then etc.
Now it toke me alot time to change all current settings to new one, and got over 1000 lines of code in the On Timer.
But isn't there a method for setup timer/wait in AMS, but only the On Timer event for each page? It would be very handy, to put script for each object instead of setting scripts for all objects on 1 page :rolleyes

But thanks for your replies !
I will stay at that method for now :yes

Kind Regards,
Casper

Intrigued
11-23-2006, 02:28 AM
Now it toke me alot time to change all current settings to new one

What are you changing? Also, if you had more timers you would have to code more anyway and not only in one spot, but working with each object you want to have a timer for.

Finally, for what it's worth... this has been put into the database as a suggestion. (I've suggested it and others have).

After thought:

Though I am not following you about the "change all current settings" with regards to multiple timers, you may find it easier to code functions with arguments in the Global Functions area and then just "call" (use) them (and change them) in the On Timer event area.

Best of luck with you project(s).

usernameCasper
11-23-2006, 02:55 AM
Hey Intrigued,

Yes, the settings in one page that use the timerevent.
I changed my mind, I will call the functions for the methods I used.
Making functions will become handy for low-line codes for in the On Timer tab.
Im putting the functions in the On Timer tab and put the code of the functions in the global declaration tab.
Yes, I made a database for myself for using some kind of information.
And i got 3 on timer functions on first page.
For flash (for x seconds, start Flash animation).
For Progressbar (loading app -nextpages-).
For automaticlogout (after x seconds).

I putted the code in the preload (ive changed that after its not working combining 3 timerevents on 1 page with using different values in the On Time)
Example: flash goes after 3 seconds, startTimer set on 3000ms, with putting flashCounter = flashCounter + 1;
If the flashCounter reach 10 (if flashCounter == 10 then ...) then it will stopTimer. Now other objectTimers need to go on, on the timerEvent.
Thats why i putted booleans to each timerobject on timer event.
Example: On Preload (function flashVerify(), flashGiveGo = true, starTimer, etc). On Time (if flashGiveGo == true then ...) then it performs actions.
If counter reach 10 than flashGiveGo = false; etc.
But that Timer is still ticking !!!
the 3 objects need to be combine, but at least 2 are combined in the On Time, needs to be FUNCTION APART/SEPERATELY from eachother,
so if i want to stop the timer in this page, i only can call the stopTimer in automatet loggoff or stopTimer in progressbar.
Thats why I wanted to make it a function apart from the On Time (new method) for update AMS or AMS 7. For example making 20 timeobjects on 1 page, and 10 needs to have a stopTimer, while some others need to have the timer STILL running !

Just to get you the idea ;):cool

Kind Regards,
Casper

usernameCasper
11-23-2006, 04:52 AM
Here's what I use for Page timers.

I normally set the page timer "on Preload" Page.StartTimer(4000); -- this timer will fire every 4 seconds

Then on the page script tab "on Timer", through scripting, you can do whatever you want to the objects on the page (every 4 seconds), or whatever duration you want to set.

Search "timer" for some very good examples of using the Page Timer, and techniques for setting up multiple timers on a page.


I hope this helps.


Hey holtgrewe,

Yes, I already know how to set this function, its already integrated into my app, but the question was how to set it as an apart function into AMS.
See above post for the 'idea'.
Btw, thanks for your reply :)

Sincerely,
Casper

Intrigued
11-23-2006, 11:54 AM
usernameCasper, what I do is set a variable (aka. "flag", ie. strFinished = false, or numCount = 0) before, increment it in the On Timer event area and then check off of that. Wether it's TRUE/FALSE or < 0, >0... it's the same idea.

usernameCasper
11-23-2006, 02:49 PM
Hey Intrigued,

Yes, I did that 2.
I made functions with booleans in them on Preload refering to On Timer.
I also made a counter.
I setted timer to 0,25 seconds for refresh or call On Timer.
Btw, I coded over 1 hour to put my objects in On Timer, cause some objects needs 0,25 sec refresh time, and others need 1,75 sec for example.
I used the Math method.
It isnt a problem, only it isnt handy ;) Its such a mess in my code over 400 lines in On Timer, lol ...
But its functional without errors at all, rather be a perfectionist as a fast coder :/
Ive been using that when I posted a reply couple posts before this one. :lol

Thanks for your replies and supporting :yes :)
Greets,
Casper

usernameCasper
11-24-2006, 06:15 AM
For the ones who dont know what im talking about or who not have a good idea what I mean, I refer to: http://www.indigorose.com/forums/showthread.php?t=17968

holtgrewe
11-28-2006, 08:17 PM
This post may get the creative juices flowing on multiple timers.

http://www.indigorose.com/forums/showthread.php?t=17968

usernameCasper
11-30-2006, 02:46 AM
This post may get the creative juices flowing on multiple timers.

http://www.indigorose.com/forums/showthread.php?t=17968

Hey holtgrewe,
It isnt multiple timers, its single ;)
And thats the problem im talking in those posts about.

holtgrewe
11-30-2006, 09:43 AM
usernameCasper,
I understand exactly what you're suggesting.

All I'm saying is that by using creative techniques, a developer can set up any number of programmatic timers as necessary.

The Page.StartTimer() merely sets the interval for checking the On Timer event.

...just another thought on timers:

It should be fairly simple to create our own event timers.
This example shows a timer based on a button being 'clicked'

On Preload set
button_1_timer=nil; Page.StartTimer(500);

On Click event,
button_1_timer=0

On timer event,
if button_1_timer ~= nil then
button_1_timer = button_1_timer + {some duration interval} -- checking every half second
if button_1_timer == {some target interval} then
--do your scripting
button_1_interval=nil;
end
end

Obviously multiple timers would be easier to deal with; however I've been creating my own.

usernameCasper
11-30-2006, 02:48 PM
You creating your own multiple timers in AMS?
Well, how you do that without imports of dll's ?
Cause that would be nice, IR staff told me multiple timers arent included yet in AMS, but it's suggested in the db :huh :rolleyes

Correct me if im wrong :p
Good luck holtgrewe.

Kind Regards,
Casper

usernameCasper
12-01-2006, 03:07 AM
Hey holtgrewe,

I hope you realise what you're saying in this statement:

All I'm saying is that by using creative techniques, a developer can set up any number of programmatic timers as necessary.

The Page.StartTimer() merely sets the interval for checking the On Timer event.


Code:

...just another thought on timers:

It should be fairly simple to create our own event timers.
This example shows a timer based on a button being 'clicked'

On Preload set
button_1_timer=nil; Page.StartTimer(500);

On Click event,
button_1_timer=0

On timer event,
if button_1_timer ~= nil then
button_1_timer = button_1_timer + {some duration interval} -- checking every half second
if button_1_timer == {some target interval} then
--do your scripting
button_1_interval=nil;
end
end



This means you manipulate the timer, while the timer interval must remain the same ! Timer must not be maniputaled !
Cause for every x ms, actions will be performed.

Btw, as told over 3 times, i dont wanna perform timer event based on an object, but on x ms. See referring postlink in this post (not to blame you at all, its alot of text for explanation, maybe overreading).

You can solve this at 2 points IMO (which include alot more scripting than the use of multiple timers, esspecially when you have much timer events):
By using Math and by using for ..,..,.. do (for the need to display (Paragraph.SetText()) every 500 ms, where interval timer is 250 ms) and flashobject perform actions every 3000 ms until pageStop.
As you can see, LOOPING method will be performed, not scripting if 0,5 or 1 or 1,5 then ... get what i mean ? ...
Thats why you use the Math function for every second, but what if you want to performAction on 500 ms, you can tell me you perform action for "if 0,5 or 1 or 1,5 then" or you prefer rather a good script? I choise for the last, i realised this on the last method before i posted this post (GLADLY) but if you need performAction for every 0,5 second - thats an example question - WITHOUT the use of arrays or setted up variables as "if 0,5 or 1 or 1,5 then".
I hope you know what i mean.

Kind Regards,
Casper

holtgrewe
12-01-2006, 08:50 AM
I hate to keep beating this into the ground; but I don't think I did a very good job in making my point on the use of multiple timers. I think multiple timers are easily obtained through AMS6.

I havn't tested the following code - I'm not on my development system right now - it may have to be tweaked and polished; but should work for using multiple timers.

On Preload:
-- >>>>> setup timer invervals for firing multiple timed events.
-- >>>>> set up 6 timers
myTimers_Max=6
-- >>>>> set up a duration for when each timer should be fired
myTimers_Duration={5000,1800,1400,300,800,1000}
-- >>>>> Set up an interval counter for each timer
myTimers_Interval={0,0,0,0,0,0]
Page.StartTimer(100);
pgTimer_Counter=100


On Timer:
-- >>>>> increment the interval for each timer
for x = 1, myTimers_Max do
myTimers_Interval[x] = myTimers_Interval[x] + pgTimer_Counter
end

-- >>>>> check if Individual timer event should be fired
for x = 1, myTimers_Max do
if myTimers_Interval[x] >= myTimers_Duration[x] then
myTimers_Interval[x] = 0; --clear the interval counter & get ready for next time
myTimer_Funct(x); -- execute the function for timer [x]
end
end

Global Function
function myTimer_Funct(whichTimer)
if whichTimer = 1 then
-- >>>>> timer1 scripting
end
--etc. for the other timers

I hope this helps anyone who may be having issues with invoking multiple timers. And if the code is correct, it can be tweaked for one or more timed events. I typically only use 2 (one for photos and one for my music).

Intrigued
12-01-2006, 10:52 AM
@Holtgrewe, :yes

usernameCasper
12-01-2006, 12:21 PM
Hey holtgrewe,

Thats a nice post, good job done by holtgrewe, thats more complexer but the space of scripts is drastically decreased :cool
And i like the script too, another golden thumb to holtgrewe :yes
Thanks mate, and thank you too Intrigued for braining together :)
Im pretty new to AMS, dont know all of the functions/methods/statements/etc., but learned alot this week, made a db for films,audio,files, etc. (still Alpha) because of the good willing people in here :)
Glad it looks similar in some ways to C++ what i do on work, but helping is never wrong, or it tokes me alot more time to find out the method holtgrewe used :yes :D, never thought of that !
Thanks again guys ! :):yes

P.S. : Now its clear what you mean holtgrewe :lol

Kind Regards,
Casper


Ohh, almost forgot to put my code in, here it is (still a mess yet :p):


ON PRELOAD

tblMenu = Application.GetMenu();
tblMenu[1].Enabled = false;
tblMenu[2].Enabled = false;
Application.SetMenu(tblMenu);

real_passwordEncryptedString = Crypto.BlowfishEncryptString("qqq","real_passwordSleutel");
real_usernameEncryptedString = Crypto.BlowfishEncryptString("111","real_usernameSleutel");
--------------------------------
--------------------------------
function startTimer()
timeInSec = 0;
Page.StartTimer(250);
end

function stopTimer() --NIET nodig
timeInSec = 0;
Page.StopTimer();
end
--------------------------------
--------------------------------
function flashPlay()
givePermission2 = true;
--Page.StartTimer("3000"); --KAN NIET meer ...
end

function flashStop()
givePermission2 = false;
Flash.Stop("Flash2");
--Page.StopTimer();
end

function getVerifyFlash()
flashProp2 = Flash.GetProperties("Flash2");
flashProp2_ObjName = flashProp2.ObjectName
flashProp2_Enabled = flashProp2.Enabled
end

--------------------------------
function autoUitloggen()
givePermission3 = true;
autoUitloggenSecLeft = 30;
--Page.StartTimer(1000); --KAN NIET meer ...
end



ON TIMER

timeInSec = (timeInSec + 1 / 4);

----------------------------
-- Function: getVerifyFlash(); (inclusief: function flashPlay();,function flashStop();,
if flashProp2_ObjName == "Flash2" and flashProp2_Enabled == true then
flashPlay();
else
flashStop();
Dialog.Message("Foutmelding","Verkeerde Code In:".."\n".."function getVerifyFlash()".."\n".."Vervang Code !", MB_OK,MB_ICONEXCLAMATION,MB_DEFBUTTON1);
end

if givePermission2 == true then
counterTime = timeInSec/3;
--||counterTimeRate = {1,2,3,4} --FOR FUN :/
-- Start 4 keer flashanimatie. Als je oneindig wil, gebruik dan repeat en untill (en while
-- en do of for en do of return of iets dergelijks,
-- zoals if counterTime == 10 then counterTime == 0)
if counterTime == 1 or counterTime == 4 or counterTime == 7 or counterTime == 10 then
Flash.Play("Flash2");
--||Input.SetText("Input4",counterTimeRate[3]); --FOR FUN :)
--Dialog.Message("SUC6", "SUCCESFULL !", MB_OK,MB_ICONINFORMATION); --FOR FUN :)
else if counterTime > 10 then
givePermission2 = false;
--flashStop();
--Page.StopTimer(); --Already declared and init in the On Show Tab !! but extra :)
--Dialog.Message("Ready", "Klaar !", MB_OK,MB_ICONINFORMATION); --FOR FUN :)
end
end
end
--[[ OF DEZE LANGERE METHODE !! / Or this longer method !!
if givePermission2 == true then
counterTime = counterTime + 1;
counterTimeValid = {1,4,7,10};
if counterTime == counterTimeValid[1] then --of On Show: Page.StartTimer(3000); en On Timer: if counterTime > 15 then givePermission0 = false;
Flash.Play("Flash2"); --or On Show: Page.StartTimer(3000); and On Timer: if counterTime > 15 then givePermission0 = false;
Paragraph.SetText("Paragraph1",counterTime); --.."");
else Flash.Stop("Flash2");
if counterTime == counterTimeValid[2] then --of On Show: Page.StartTimer(12000); en On Timer: if counterTime > 15 then givePermission0 = false;
Flash.Play("Flash2"); --etc..
Paragraph.SetText("Paragraph1",counterTime.."");
else Flash.Stop("Flash2");
if counterTime == counterTimeValid[3] then
Flash.Play("Flash2");
Paragraph.SetText("Paragraph1",counterTime.."");
else Flash.Stop("Flash2");
if counterTime == counterTimeValid[4] then
Flash.Play("Flash2");
Paragraph.SetText("Paragraph1",counterTime.."");
else givePermission0 = false;
end
end
end
end
end
--]]
----------------------------------------------------------------------------------------------------------------------------------------------
-- Function: OnClickButton(Login !)
if timeInSec >= 0 then
if givePermission1 == true then
Progress.SetRange("Progress1",0,120);
currentPos = Progress.GetCurrentPos("Progress1");
if currentPos < 119 then
Progress.SetCurrentPos("Progress1", currentPos + 10);
nCurrentPos = Progress.GetCurrentPos("Progress1");

tRange = Progress.GetRange("Progress1");

nPercentComplete = ((nCurrentPos - tRange.Begin) / (tRange.End - tRange.Begin)) * 100;
nPercentCompleteAfgerond = Math.Floor(nPercentComplete);

Progress.SetText("Progress1", nPercentCompleteAfgerond .. "%");
else
givePermission1 = false;
Page.StopTimer();
end
end
--Progress.SetStep("Progress1",10);
--Progress.StepIt("Progress1");
end
----------------
--Aangeroepen door function startPageTimer2() / called by function startPageTimer2()
----------------
----------------------------------------------------------------------------------------------------------------------------------------------
-- Function: autoUitloggen();
if timeInSec >= 0 and timeInSec == Math.Round(timeInSec,0) then
if givePermission3 == true then
autoUitloggenSecLeft = autoUitloggenSecLeft -1;
autoUitloggenText = "Uitloggen in: " .. autoUitloggenSecLeft .."";
Paragraph.SetText("Paragraph4",autoUitloggenText);
if autoUitloggenSecLeft == 0 then
Page.StopTimer();
Dialog.TimedMessage("Automatisch Uitloggen","U heeft niet binnen 30 seconden ingelogd.\nApplicatie sluit daarom af !",5000,MB_ICONSTOP);
Application.Exit();
end
end
end

Look at the Math.Round, it can be done by this, setting up Array or setting them individually (lot of scripts, big mess for large project).

Another P.S.: "You have included 11 images in your message. You are limited to using 10 images so please go back and correct the problem and then continue again.

Images include use of smilies, the vB code [img] tag and HTML <img> tags. The use of these is all subject to them being enabled by the administrator."
I've decreased my smilies, to big post i think :/