PDA

View Full Version : LUA dummy here - please help!



maxthebuilder
December 11th, 2007, 11:03 PM
Hello,
I have this lua code in ccf lua script (thanks to the author!) which switches off PPC's screen after 60 sec of inactivity.
I tried to modify it so that it would only work if the PPC runs on batteries (i.e. when running on AC power, the screen stays on all the time).
I added a piece of if-code watching the power.ac variable (1 - ac power, 0 - battery) --> now the screen stays on no matter what..
Can someone please tell me what I did wrong? I tried all kinds of variants .. ==, =, ~=, 0, '0', tonumber()...
Here's the code


if (NetRemote.GetVariable('NRCFG.Platform') == 'WINCE') then
function BlankScreen( )
if (Power.AC == '0' ) then
if (tonumber( NetRemote.GetVariable( "Utility.TimeSinceLastAction" )) > 60000) then
NetRemote.ExecuteAction( -999, 3, 4 );
end;
end;
end;

-- Create a timer to call the BlankScreen function once per minute
pScreenTime = NetRemote.SetTimer( 60000, BlankScreen );
end;
Thanks mucho!
--max

Rob H
December 12th, 2007, 12:23 AM
It depends what the type of the Power.AC variable is. I suspect that it might be a boolean so just


if not Power.AC then

would do the trick

theguywiththefunnyhair
December 12th, 2007, 01:00 AM
Hi Max,
I found when i meet something frustrating like this i can find out why it doesnt work by putting in an 'else' and making it print some info when it doesnt match the rule.


if (NetRemote.GetVariable('NRCFG.Platform') == 'WINCE') then
function BlankScreen( )
if (Power.AC == '0' ) then
if (tonumber( NetRemote.GetVariable( "Utility.TimeSinceLastAction" )) > 60000) then
NetRemote.ExecuteAction( -999, 3, 4 );
end;
else
print(Power.AC, type(Power.AC))
end;
end;

-- Create a timer to call the BlankScreen function once per minute
pScreenTime = NetRemote.SetTimer( 60000, BlankScreen );
end;
maybe next time this will help you!

maxthebuilder
December 12th, 2007, 07:45 AM
Maybe it's boolean.. I didn't try this yet..
However, i did put a framein ccf with {Power.AC} name tag on it - it shows either 1 or 0..
Thanks!


It depends what the type of the Power.AC variable is. I suspect that it might be a boolean so just


if not Power.AC then

would do the trick

maxthebuilder
December 12th, 2007, 07:46 AM
Great! This will sure help - thanks!


Hi Max,
I found when i meet something frustrating like this i can find out why it doesnt work by putting in an 'else' and making it print some info when it doesnt match the rule.


if (NetRemote.GetVariable('NRCFG.Platform') == 'WINCE') then
function BlankScreen( )
if (Power.AC == '0' ) then
if (tonumber( NetRemote.GetVariable( "Utility.TimeSinceLastAction" )) > 60000) then
NetRemote.ExecuteAction( -999, 3, 4 );
end;
else
print(Power.AC, type(Power.AC))
end;
end;

-- Create a timer to call the BlankScreen function once per minute
pScreenTime = NetRemote.SetTimer( 60000, BlankScreen );
end;
maybe next time this will help you!

maxthebuilder
December 12th, 2007, 10:00 AM
OK.. I made it work.. print(Power.AC, type(Power.AC)) helped a lot actually.

First, print(Power.AC) didn't work at all giving me an error message! I looked in other people ccf's and found
local ac = Netremote.GetVariable('Power.AC')
(or close to this - don't remember the correct "spelling" - I am away from my computer)
After this print(ac, type(ac)) started to work returning 1 and String and I was able to fix my script (by introducing the variable inside the function)

Thanks for helping!