using timer

Find quick help here to get you started with Hollywood
User avatar
stefff285
Posts: 230
Joined: Sat Mar 03, 2012 12:59 pm
Location: dijon / france
Contact:

using timer

Post by stefff285 »

hello all hello andreas

i go use start timer and stop timer i have no indea how to use it
have i to make a function() to enclose it ? and then make a SetInterval() ?

thanx a lot for help, i go script later for a tiny wild prod for a party in france

regards

stéphane
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

Re: using timer

Post by Bugala »

Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

Re: using timer

Post by Bugala »

Reading your message again.

were you actually talking of "WaitEvent" command where you are waiting for some event to occur, but can use setinterval to make some piece of code (function) be continuously ran while waiting for event to happen?
User avatar
stefff285
Posts: 230
Joined: Sat Mar 03, 2012 12:59 pm
Location: dijon / france
Contact:

Re: using timer

Post by stefff285 »

hello bugala

in fact (at first thanx) it is a prod in which i have to display cartoon drawings one after the other and then go to the final screen with a starfield and a sinus scroll (already done by imitating another example source)
so then yes display pictures but also playing a .mod surrely made by jayblood/Vital-Motion! . so then i go to read your link. thanx a lot
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

Re: using timer

Post by Bugala »

Okay, so if it isnt waiting for "WaitEvent" to happen, as from your explanation is sounds like, then the link i put would probably be what you are looking for.

Let me know if it is about "waitevent" after all, and i will try to make some short example about that interval.
User avatar
stefff285
Posts: 230
Joined: Sat Mar 03, 2012 12:59 pm
Location: dijon / france
Contact:

Re: using timer

Post by stefff285 »

hello my dear bugala how are you

ys i simply would like to display some 30 or more images as this

starttimer(1, 400)
displaybrush(1, 0, 0)
stoptimer(1)
starttimer(2, 400)
displaybrush(2, 0, 0)

and so on

thanx a lot

stéphane
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

Re: using timer

Post by Bugala »

Still not completely sure, but looks like you are trying to use setinterval, not the timer.

So what timer does is this: (Im not sure this works, as this is just theoretical)

Code: Select all

Starttimer(1)
...
do stuff
...
a = Gettimer(1)
print(a)
results in for example number 100 printed out, supposing it took 100 milliseconds to run it.

Idea in this example is, that you are like having one of those stopwatches they use in sports to measure how long it took for someone to run the distance. This stopwatch you have is numbered as number 1. When you use command "Starttimer(1)" it tells hollywood to push the button of stopwatch number 1, which means that the number on that watchclock starts increasing.

Then you do what ever stuff you do, and finally you use command "Gettimer(1)" to get the time that watchclock number 1 is at that moment showing.

So if it took runner 10 seconds to run the 100 meters, then the stopwatch will be showing 10 seconds in it.

Bu using "resettimer(1)" it will tell to reset the stopwatch number 1 back to 0 and start its timing from beginning.


But what I believe you are after is following:

Code: Select all

Function MyFunc()
debugprint("hello world")
EndFunction

setinterval(1, MyFunc, 1000)
WaitEvent
What this code does in practice, is to print "Hello World" once a second.

Idea is that code is halter until some event happens. As there is no event to happen, this code will continue for ever.

However, before "WaitEvent" happens, I have used "Setinterval" command to set something to happen while waiting for that event to happen.

SetInterval has three arguments. First one is the ID for this interval (soon more about that), second argument tells which function should be the function to be executed while waiting for event to happen. and third one tells how often this function should be executed, where 1 000 is same as once in 1 000 milliseconds = once per second.

If you put third argument as 1, then that function will be executed once per millisecond, which is very fast.

Notice, that although you might want something to be executed once per millisecond, it might not in practice be executed that fast. For the point with that number is that Hollywood tries to execute it that fast, but might be you computer is not fast enough to do that function once every millisecond, in which case it will simply be executed as often as possible.

To get back to ID part, you can have several intervals executed while WaitEvent is happening:

Code: Select all

Function MyFirstFunc()
debugprint("hello world")
EndFunction

Function MySecondFunc()
debugprint("Second funtion")
EndFunction

setinterval(1, MyFirstFunc, 1000)
SetInterval(2, MySecondFunc, 500)
WaitEvent
This would result in something like:
Second Function
Second function
Hello World
Second Funtion
Second function
Hello world
second funtion
second funtion
hello world
...

Reason for this is that it tells to execute MySecondFunc every half a second, which results in debugprinting "second function" while executing MyFirstFunc only once per second.

Notice that these both have own ID, this means that if there would come "ClearInterval(2)" then after that point, MySecondFunc wouldnt be executed anymore at waitevent, but only MyFirstFunc which has ID 1 would be exexcuted anymore.


To achieve what I think you are looking to achieve, It seems solution would be something like this:

Code: Select all

a=0

Function p_ChangePicture
A=A + 1
IF A=30 then A = 0
DisplayBrush(A, 0, 0)
EndFunction

SetInterval(1, p_ChangePicture, 400)

waitevent()
Now it would keep displaying different picture every 400 milliseconds (2.5 times per second). If you wish the change take longer, just change the 400 to something bigger.

Idea is that you will be having variable A which would be storing a number. At beginning you set it to 0.

Each time this p_ChangePicture function is executed variable A is increased by 1. In case variable A reaches number 30 (you said 30 pictures), then it is changed back to 0.

After this variable A is used in displaying brush, which means it will be different brush each time, since A will be different each time.

Was this what you needed?
User avatar
stefff285
Posts: 230
Joined: Sat Mar 03, 2012 12:59 pm
Location: dijon / france
Contact:

Re: using timer

Post by stefff285 »

hello bugala

at first thanx a lot for awnsers and hooooooooooooooo many :)))
yes going to test last one, with time_function() but do you think the time will be the same on a g4 and a i7 for example ?
if yes then i go to code it this afternoon

thanx a lot

stéphane
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

Re: using timer

Post by Bugala »

Yes, that is exactly the idea with the timer that timer will be running at same speed in each computer, be it faster or slower. So 400 milliseconds is 400 milliseconds both in A500 as well as in X1000.
User avatar
stefff285
Posts: 230
Joined: Sat Mar 03, 2012 12:59 pm
Location: dijon / france
Contact:

Re: using timer

Post by stefff285 »

ok ! thanx so lot ! so i go script it this afternoon

thanx my friend

stéphane
Post Reply