PDA

View Full Version : Timer To Wake Me Up? No variables in AlarmTimer :(



tmartins
August 29th, 2003, 08:12 PM
I want to use my remote control to set the time when my pc wakes me up.

TimeToString plugin gives me the current time ok, NumBuilder lets me input the new time. Lua calculates the difference in milliseconds between those two times. So far so good, but....

What timer system should I use to actually fire the wake up? AlarmTimer does not support variables so I cannot put my milliseconds there as a variable.

I'd be happy if someone could help me. I couldn't figure this out.

Thanks guys, and thanks Ron for a GREAT software!!

Tomas

Bitmonster
August 30th, 2003, 12:57 AM
Marc wants to implement timer functions in WinLUAEx, so stay tuned what comes in the next release.

I use a lot of variable timing in my setup and so I developed a workaround. I use one timer and made commands for 10ms, 100ms, 1000 ms, 10 sec timers. Then I wrote some LUA code to calculate which timer would be best used to get near the desired time. After this timer has completed, the script calculates the next step and again uses one appropiate timer. This process continues till the wanted time has been exceeded and then fires the actual event you want (or executes a LUA function).

As you can see, this is really a mess, but it works. This way I can make an unlimited amount of different timers and I only need one alarmtimer ID.

If you can't wait, till Marc finished his work, I can send you my code.

tmartins
August 30th, 2003, 06:48 AM
Thanks!
I will send you an email!

Tomas

Bitmonster
August 30th, 2003, 08:29 AM
You can download the needed files here (http://www.bitmonster.com/girder/bitmonster.zip).

To use it you have to:
- Enable the AlarmTimer plugin and make sure you don't use AlarmTimerID 7 anywhere else.
- Install and enable the recent WinLUAEx Plugin.
- Import the "Bitmonster's Tool Functions.GML".
- Restart Girder


The function you need is "AddTimer":
function AddTimer(func, delay, data)

func = a function to call (explanation later)
delay = number of milliseconds to wait
data = data to the function func. (optional)

The function "func" only needs one parameter and that is the "data" you first might have supplied to AddTimer. If the "func" returns a numeric value, this is used to call it again after this time in milliseconds. If it returns nil, this is an one-shot-timer. So a simple func and call to AddTimer looks like this.

function myFunc(data)
TriggerEvent(data, 18)
return 10000
end

AddTimer(myFunc, 1000, "myEvent")

This will wait 1 second till it will fire the girder-event with eventstring "myEvent". After that it will repeat this event every 10 seconds.

If you want to discard a running timer, you can call:
RemoveTimer(func, data)
Use the same parameters as to the call to AddTimer. So to stop this example you have to call:
RemoveTimer(myFunc, "myEvent")

Let me know, if you can get this working. :)

Bitmonster
August 30th, 2003, 08:48 AM
@tmartins
Your email-address in the mail you sent me is wrong. My mail returned with "User unknown".

tmartins
August 30th, 2003, 04:18 PM
The email thing is weird, I sent an email to myself and clicked reply. My address was ok there. Weird.

Well its better that the solution is here as it will shurely help others too.

Now I'll skip my satruday night's partys and play with your code instead :)

I'll post here later and tell how it went.

Tomas

tmartins
August 30th, 2003, 07:39 PM
I got your code working. Very well structured code. Throw in a few more comments and that's perfect.

Your system was pretty advanced, so I ended up doing a simple plain vanilla version of the same thing using your idea. Works like a charm. I also learned a few lua things by looking at your code. It is nice to see that some people make good code even when using scripting languages :D I might get back to your advanced version if and when my system grows up.

Thanks!!!

Tomas

Bitmonster
August 30th, 2003, 08:35 PM
Thank you very much for the compliment.

Actually it started more as a quick-n-dirty-hack. :)
If Marc releases his new timer-functions I will anyway have to rework the code.