PDA

View Full Version : how to sleep/wait in a lua script?



dandiodati
February 1st, 2005, 10:57 PM
I'm to find out if there is a way to do a sleep/wait for a certain amount time so that I can poll the state of a remote server.

So I need to do :

while true
check state of remote server.
if not ready
sleep for some time
else
break out of loop.

I would prefer if the sleep did not take up any cpu time like doing a wait/yield on a thread.
I saw some script with NetRemote.sleep(10), and I tried this but it did not appear to do anything.

I also saw an example using coroutines and using a AddTimer method. But it turned out that the AddTimer method was not available in lua but some specific function call for some other library, so this did not work.

Is there a way to do this?

Jlee
February 2nd, 2005, 12:07 AM
Check out the latest pre-release of NR (v1.0.20), which includes documentation for AvidUtils plugin. I think that has a timer.

avid
February 2nd, 2005, 12:42 AM
JLee is right. You can't wait in a LUA script because nothing will happen while you are sleeping.

What you need to do is set a "delayed variable" using an AvidUtils action. And then use the LUA OnVariableChange function to catch the delayed set and do what you want. Until the variable changes, NR carries on as before.

I'm not in a position to give a precise recipe from memory, but that is the gist of it.

Brian

avid
February 2nd, 2005, 12:46 AM
Actually, what do you mean by "check state of remote server"?? Maybe the new feature in the NR prerelease does all you want. See http://www.promixis.com/phpBB2/viewtopic.php?t=10289&start=0 "
Enhancement - Added ability to fire an action only if a variable is set, and to wait to fire the action until the variable is set. Action is -999,5,16, with the IR name being "Variable Name,Value to wait for,Max wait in milliseconds". So to wait for Girder.LinkActive to equal 1, or timeout after 10 seconds, the IR name would be "Girder.LinkActive,1,10000"
Brian

dandiodati
February 3rd, 2005, 12:34 AM
I have a tablet that is starting the main HTPC via WOL. Once the the HTPC comes up
it starts girder and is supposed to send a request to the tablet to let it know that it is ready. I have not been able to get this to work correctly, so I was going to take the approach of having the tablet poll the server if it is ready.
Thanks for all the ideas, I'll look into them and see what I come up with.

avid
February 3rd, 2005, 12:44 AM
From what you are trying to do, it sounds as though the new enhancement will do just what you need.

Brian

dandiodati
February 4th, 2005, 09:05 AM
Ok I was trying out that new action but it does not seem to work correctly.
I am using netremote 1.0.20.0.

I tried this within a function:



local ready = Netremote.GetVariable('Girder.LinkActve');
while (ready ~= '1') do
NetRemote.ExecuteAction(-999,5,16,"Girder.LinkActive,1,10000");
NetRemote.MessageBox("here after a wait");
ready = Netremote.GetVariable('Girder.LinkActve');
end

-- jump to some panel


The wait on a variable action does not seem to work. The message box keeps popping up as fast as it can instead of every 10 seconds. I thought that this command will wait for up to 10 seconds before continuing? Or is this not how to use it?
Although the Girder.LinkActive does work and change to 1 when my HTPC starts up girder. :-).

Dan

Rob H
February 4th, 2005, 09:18 AM
I don't think that works in a LUA script, only in the action for a button.

avid
February 4th, 2005, 10:39 AM
That's right. In another thread, Ben said:
Also, just FYI: Since these 3 codes manipulate the way actions are handled, calling them from lua won't do anything (an ExecuteAction is an action list of only 1 item).
Brian

dandiodati
February 4th, 2005, 04:17 PM
Does that mean the button has to be clicked on to trigger the start of this action?

I take it I define a IR code on the button with the all of the previous information.

I'm still not quite clear how this would be used? Do I have to have other ir commands defined on the button to be of use?

Rob H
February 4th, 2005, 04:19 PM
They don't have to be other IR commands - you could put the jump that you mentioned earlier on that button.