PDA

View Full Version : FREE ACTION PLUGIN: Timer


ShadowUK
03-27-2008, 03:52 PM
Timer Action Plugin
by ShadowUK

You'll need to go to your AutoPlay Media Studio folder and navigate to Data/Actions then put this file (http://www.flameounch.com/ActionPlugins/_at_Timer.xml) in that folder.

Now you've installed the Actions, it's time to install the functions!

Go to: AutoPlay Media Studio/Data/Includes and open _notification_messages.lua

Append at the bottom the following:
Timer = {}

Timer.OldTimerCode = Application.GetPageScript(this, "On Timer")

function Timer.Create(Name, Delay, Repeats, Function)
if (type(Function) == "function") then
error("string expected, got function! ("..assert(tostring(Function))..")");
elseif (type(Function) == "number") then
error("string expected, got number! ("..assert(tostring(Function))..")");
elseif (type(Function) == "table") then
error("string expected, got table! ("..assert(tostring(Function))..")");
elseif (type(Function) == "nil") then
error("attept to local global callback function (a nil value)");
end

function DoThink()
if (Occurrences == Repeats) then
Page.StopTimer()
Occurrences = nil
end
end

if (Repeats ~= 0) then
Occurrences = 0
Application.SetPageScript(this, "On Timer", Timer.OldTimerCode.."\r\n"..Function.."\r\nOccurrences = Occurrences + 1\r\nDoThink()");
Page.StartTimer(Delay * 1000)
elseif (Repeats == 0) then
Application.SetPageScript(this, "On Timer", Timer.OldTimerCode.."\r\n"..Function);
Page.StartTimer(Delay * 1000)
end
end

function Timer.Simple(Delay, Function)
if (type(Function) == "function") then
error("string expected, got function! ("..assert(tostring(Function))..")");
elseif (type(Function) == "number") then
error("string expected, got number! ("..assert(tostring(Function))..")");
elseif (type(Function) == "table") then
error("string expected, got table! ("..assert(tostring(Function))..")");
elseif (type(Function) == "nil") then
error("attept to local global callback function (a nil value)");
end

Application.SetPageScript(this, "On Timer", Timer.OldTimerCode.."\r\n"..Function.."\r\nPage.StopTimer()\r\nApplication.SetPageScript( Application.GetCurrentPage(), \"On Timer\", \"\")")
Page.StartTimer(Delay / 1000)
end

Save the file and off you go! Plugin installed!

Later down the line, I should consider creating an automatic plugin installer if I can't be bothered to use the real plugin method.

Worm
03-27-2008, 05:09 PM
neat concept... Nice outa-the-box thinking :yes

holtgrewe
03-27-2008, 06:43 PM
This has great potential; however after install:

Error
Startup, Line 790: Argument 1 must be type string.


This was on the compile of an existing project before ever using the Timer function.

ShadowUK
03-28-2008, 01:32 AM
Yeh, I seem to find this as well. I need to find out how to fix it first, I may have corrupted something in the core code.

Edit:

Nothing wrong with the code, But It might be the Actions file. In the mean time while I get this fixed please don't download it yet.

ShadowUK
03-28-2008, 01:52 AM
Well, you can always use the code as normal. While I get working on this again.

rexzooly
03-28-2008, 08:04 AM
Well, you can always use the code as normal. While I get working on this again.

i am keeping a eye this hope it becomes working soon so i can mirror it for you
:)

Worm
03-28-2008, 09:57 AM
ShadowUK, this is only creating a branch within the current Page Timer, correct? If you have a "timer function" that is costly in time, the functions below them will be delayed that much longer, correct?

ShadowUK
03-28-2008, 11:24 AM
It's an alternative to Application.Sleep, And I think I messed up in the XML, I'll be recoding this again.